cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] android commit: CB-8329 Cancel outstanding ActivityResult requests when a new startActivityForResult occurs
Date Mon, 19 Jan 2015 21:23:28 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/3.7.x cfc36140b -> 5538a231a


CB-8329 Cancel outstanding ActivityResult requests when a new startActivityForResult occurs


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/9be11068
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/9be11068
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/9be11068

Branch: refs/heads/3.7.x
Commit: 9be110683b31a9ce491d97386a29d716a3379438
Parents: cfc3614
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Jan 19 16:13:48 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Jan 19 16:23:19 2015 -0500

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java | 34 ++++++++++++++++----
 1 file changed, 27 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9be11068/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index b61fa98..6a3c70b 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -103,7 +103,8 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
     private int activityState = 0;  // 0=starting, 1=running (after 1st resume), 2=shutting
down
 
     // Plugin to call when activity result is received
-    protected CordovaPlugin activityResultCallback = null;
+    protected int activityResultRequestCode;
+    protected CordovaPlugin activityResultCallback;
     protected boolean activityResultKeepRunning;
 
     /*
@@ -666,7 +667,7 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
      * @param requestCode       The request code that is passed to callback to identify the
activity
      */
     public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode)
{
-        this.activityResultCallback = command;
+        setActivityResultCallback(command);
         this.activityResultKeepRunning = this.keepRunning;
 
         // If multitasking turned on, then disable it for activities that return results
@@ -674,8 +675,19 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
             this.keepRunning = false;
         }
 
-        // Start activity
-        super.startActivityForResult(intent, requestCode);
+        try {
+            startActivityForResult(intent, requestCode);
+        } catch (RuntimeException e) { // E.g.: ActivityNotFoundException
+            activityResultCallback = null;
+            throw e;
+        }
+    }
+
+    @Override
+    public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
+        // Capture requestCode here so that it is captured in the setActivityResultCallback()
case.
+        activityResultRequestCode = requestCode;
+        super.startActivityForResult(intent, requestCode, options);
     }
 
     /**
@@ -706,16 +718,24 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
         if(callback == null && initCallbackClass != null) {
             // The application was restarted, but had defined an initial callback
             // before being shut down.
-            this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
-            callback = this.activityResultCallback;
+            callback = appView.pluginManager.getPlugin(initCallbackClass);
         }
-        if(callback != null) {
+        initCallbackClass = null;
+        activityResultCallback = null;
+
+        if (callback != null) {
             LOG.d(TAG, "We have a callback to send this result to");
             callback.onActivityResult(requestCode, resultCode, intent);
+        } else {
+            LOG.w(TAG, "Got an activity result, but no plugin was registered to receive it.");
         }
     }
 
     public void setActivityResultCallback(CordovaPlugin plugin) {
+        // Cancel any previously pending activity.
+        if (activityResultCallback != null) {
+            activityResultCallback.onActivityResult(activityResultRequestCode, Activity.RESULT_CANCELED,
null);
+        }
         this.activityResultCallback = plugin;
     }
 


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


Mime
View raw message