cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: CB-8827 Call onResume for plugins on start-up
Date Thu, 09 Apr 2015 01:06:42 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 2e9cbdcb0 -> 0f73884c8


CB-8827 Call onResume for plugins on start-up

As a result, simplifies CordovaActivity by removing the now unused "activityState" field


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

Branch: refs/heads/master
Commit: 0f73884c8d93d071aa763079825b576ca493bf96
Parents: 2e9cbdc
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Apr 8 21:03:32 2015 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Apr 8 21:06:23 2015 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java | 31 ++------------------
 .../org/apache/cordova/CordovaWebViewImpl.java  |  8 +++--
 .../apache/cordova/test/CordovaPluginTest.java  |  2 +-
 3 files changed, 9 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0f73884c/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 43a68e6..45254b3 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -82,7 +82,6 @@ public class CordovaActivity extends Activity {
     private static int ACTIVITY_STARTING = 0;
     private static int ACTIVITY_RUNNING = 1;
     private static int ACTIVITY_EXITING = 2;
-    private int activityState = 0;  // 0=starting, 1=running (after 1st resume), 2=shutting
down
 
     // Keep app running when pause is received. (default = true)
     // If true, then the JavaScript and native code continue to run in the background
@@ -224,11 +223,6 @@ public class CordovaActivity extends Activity {
         super.onPause();
         LOG.d(TAG, "Paused the activity.");
 
-        // Don't process pause if shutting down, since onDestroy() will be called
-        if (this.activityState == ACTIVITY_EXITING) {
-            return;
-        }
-
         if (this.appView != null) {
             this.appView.handlePause(this.keepRunning);
         }
@@ -253,11 +247,6 @@ public class CordovaActivity extends Activity {
         super.onResume();
         LOG.d(TAG, "Resumed the activity.");
         
-        if (this.activityState == ACTIVITY_STARTING) {
-            this.activityState = ACTIVITY_RUNNING;
-            return;
-        }
-
         if (this.appView == null) {
             return;
         }
@@ -307,22 +296,6 @@ public class CordovaActivity extends Activity {
         if (this.appView != null) {
             appView.handleDestroy();
         }
-        else {
-            this.activityState = ACTIVITY_EXITING; 
-        }
-    }
-
-    /**
-     * End this activity by calling finish for activity
-     */
-    public void endActivity() {
-        finish();
-    }
-
-    @Override
-    public void finish() {
-        this.activityState = ACTIVITY_EXITING;
-        super.finish();
     }
 
     @Override
@@ -400,7 +373,7 @@ public class CordovaActivity extends Activity {
                                 public void onClick(DialogInterface dialog, int which) {
                                     dialog.dismiss();
                                     if (exit) {
-                                        me.endActivity();
+                                        finish();
                                     }
                                 }
                             });
@@ -460,7 +433,7 @@ public class CordovaActivity extends Activity {
                 e.printStackTrace();
             }
         } else if ("exit".equals(id)) {
-            this.endActivity();
+            finish();
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0f73884c/framework/src/org/apache/cordova/CordovaWebViewImpl.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index a336e12..06da55e 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -61,7 +61,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
     private CoreAndroid appPlugin;
     private NativeToJsMessageQueue nativeToJsMessageQueue;
     private EngineClient engineClient = new EngineClient();
-    private Context context;
+    private boolean hasPausedEver;
 
     // The URL passed to loadUrl(), not necessarily the URL of the current page.
     String loadedUrl;
@@ -426,6 +426,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
         if (!isInitialized()) {
             return;
         }
+        hasPausedEver = true;
         pluginManager.onPause(keepRunning);
         sendJavascriptEvent("pause");
 
@@ -444,7 +445,10 @@ public class CordovaWebViewImpl implements CordovaWebView {
         // Resume JavaScript timers. This affects all webviews within the app!
         engine.setPaused(false);
         this.pluginManager.onResume(keepRunning);
-        sendJavascriptEvent("resume");
+        // To be the same as other platforms, fire this event only when resumed after a "pause".
+        if (hasPausedEver) {
+            sendJavascriptEvent("resume");
+        }
     }
     @Override
     public void handleStart() {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0f73884c/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java
----------------------------------------------------------------------
diff --git a/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java b/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java
index f9f254a..39a45d5 100644
--- a/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java
+++ b/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java
@@ -58,7 +58,7 @@ public class CordovaPluginTest extends BaseCordovaIntegrationTest {
         //currently only one of the cases is covered
         LifeCyclePlugin testPlugin = (LifeCyclePlugin)cordovaWebView.getPluginManager().getPlugin("LifeCycle");
 
-        assertEquals("start,pause,stop,", testPlugin.calls);
+        assertEquals("start,resume,pause,stop,", testPlugin.calls);
         testPlugin.calls = "";
         // testOnStart
         invokeBlockingCallToLifeCycleEvent("callActivityOnStart");


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


Mime
View raw message