cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rkn...@apache.org
Subject cordova-plugin-contacts git commit: CB-10159 android: Adding restore callback to handle Activity destruction
Date Thu, 14 Jan 2016 00:42:39 GMT
Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master 077631e82 -> 00f71a8aa


CB-10159 android: Adding restore callback to handle Activity destruction


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/00f71a8a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/00f71a8a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/00f71a8a

Branch: refs/heads/master
Commit: 00f71a8aafeb26d8172cb77833e7cc6fec7d905c
Parents: 077631e
Author: riknoll <richard.b.knoll@gmail.com>
Authored: Mon Dec 7 14:54:22 2015 -0800
Committer: riknoll <richard.b.knoll@gmail.com>
Committed: Wed Jan 13 14:54:28 2016 -0800

----------------------------------------------------------------------
 README.md                       | 21 +++++++++++++++++++++
 src/android/ContactManager.java | 11 +++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/00f71a8a/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 2279173..77e8c88 100644
--- a/README.md
+++ b/README.md
@@ -227,6 +227,27 @@ function specified by the __contactSuccess__ parameter.
             console.log('Error: ' + err);
         });
 
+### Android Quirks
+
+This plugin launches an external Activity for picking contacts. See the
+[Android Lifecycle Guide](http://cordova.apache.org/docs/en/dev/guide/platforms/android/lifecycle.html)
+for an explanation of how this affects your application. If the plugin returns
+its result in the `resume` event, then you must first wrap the returned object
+in a `Contact` object before using it. Here is an example:
+
+```javascript
+function onResume(resumeEvent) {
+    if(resumeEvent.pendingResult) {
+        if(resumeEvent.pendingResult.pluginStatus === "OK") {
+            var contact = navigator.contacts.create(resumeEvent.pendingResult.result);
+            successCallback(contact);
+        } else {
+            failCallback(resumeEvent.pendingResult.result);
+        }
+    }
+}
+```
+
 ## Contact
 
 The `Contact` object represents a user's contact.  Contacts can be

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/00f71a8a/src/android/ContactManager.java
----------------------------------------------------------------------
diff --git a/src/android/ContactManager.java b/src/android/ContactManager.java
index d8f611b..448302d 100644
--- a/src/android/ContactManager.java
+++ b/src/android/ContactManager.java
@@ -32,6 +32,7 @@ import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.os.Build;
+import android.os.Bundle;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.RawContacts;
 import android.util.Log;
@@ -292,4 +293,14 @@ public class ContactManager extends CordovaPlugin {
         }
     }
 
+    /**
+     * This plugin launches an external Activity when a contact is picked, so we
+     * need to implement the save/restore API in case the Activity gets killed
+     * by the OS while it's in the background. We don't actually save anything
+     * because picking a contact doesn't take in any arguments.
+     */
+    public void onRestoreStateForActivityResult(Bundle state, CallbackContext callbackContext)
{
+        this.callbackContext = callbackContext;
+        this.contactAccessor = new ContactAccessorSdk5(this.cordova);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message