From 0f73884c8d93d071aa763079825b576ca493bf96 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Wed, 8 Apr 2015 21:03:32 -0400 Subject: [PATCH] CB-8827 Call onResume for plugins on start-up As a result, simplifies CordovaActivity by removing the now unused "activityState" field --- .../org/apache/cordova/CordovaActivity.java | 31 ++----------------- .../apache/cordova/CordovaWebViewImpl.java | 8 +++-- .../cordova/test/CordovaPluginTest.java | 2 +- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 43a68e6a..45254b33 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; } diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index a336e123..06da55e1 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() { diff --git a/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java b/test/androidTest/src/org/apache/cordova/test/CordovaPluginTest.java index f9f254aa..39a45d5c 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");