CB-8827 Call onResume for plugins on start-up

As a result, simplifies CordovaActivity by removing the now unused "activityState" field
This commit is contained in:
Andrew Grieve 2015-04-08 21:03:32 -04:00
parent 2e9cbdcb0d
commit 0f73884c8d
3 changed files with 9 additions and 32 deletions

View File

@ -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;
}

View File

@ -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() {

View File

@ -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");