mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 01:53:00 +08:00
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:
parent
2e9cbdcb0d
commit
0f73884c8d
@ -82,7 +82,6 @@ public class CordovaActivity extends Activity {
|
|||||||
private static int ACTIVITY_STARTING = 0;
|
private static int ACTIVITY_STARTING = 0;
|
||||||
private static int ACTIVITY_RUNNING = 1;
|
private static int ACTIVITY_RUNNING = 1;
|
||||||
private static int ACTIVITY_EXITING = 2;
|
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)
|
// Keep app running when pause is received. (default = true)
|
||||||
// If true, then the JavaScript and native code continue to run in the background
|
// 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();
|
super.onPause();
|
||||||
LOG.d(TAG, "Paused the activity.");
|
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) {
|
if (this.appView != null) {
|
||||||
this.appView.handlePause(this.keepRunning);
|
this.appView.handlePause(this.keepRunning);
|
||||||
}
|
}
|
||||||
@ -253,11 +247,6 @@ public class CordovaActivity extends Activity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
LOG.d(TAG, "Resumed the activity.");
|
LOG.d(TAG, "Resumed the activity.");
|
||||||
|
|
||||||
if (this.activityState == ACTIVITY_STARTING) {
|
|
||||||
this.activityState = ACTIVITY_RUNNING;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.appView == null) {
|
if (this.appView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -307,22 +296,6 @@ public class CordovaActivity extends Activity {
|
|||||||
if (this.appView != null) {
|
if (this.appView != null) {
|
||||||
appView.handleDestroy();
|
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
|
@Override
|
||||||
@ -400,7 +373,7 @@ public class CordovaActivity extends Activity {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
if (exit) {
|
if (exit) {
|
||||||
me.endActivity();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -460,7 +433,7 @@ public class CordovaActivity extends Activity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if ("exit".equals(id)) {
|
} else if ("exit".equals(id)) {
|
||||||
this.endActivity();
|
finish();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
private CoreAndroid appPlugin;
|
private CoreAndroid appPlugin;
|
||||||
private NativeToJsMessageQueue nativeToJsMessageQueue;
|
private NativeToJsMessageQueue nativeToJsMessageQueue;
|
||||||
private EngineClient engineClient = new EngineClient();
|
private EngineClient engineClient = new EngineClient();
|
||||||
private Context context;
|
private boolean hasPausedEver;
|
||||||
|
|
||||||
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
||||||
String loadedUrl;
|
String loadedUrl;
|
||||||
@ -426,6 +426,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
hasPausedEver = true;
|
||||||
pluginManager.onPause(keepRunning);
|
pluginManager.onPause(keepRunning);
|
||||||
sendJavascriptEvent("pause");
|
sendJavascriptEvent("pause");
|
||||||
|
|
||||||
@ -444,8 +445,11 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
// Resume JavaScript timers. This affects all webviews within the app!
|
// Resume JavaScript timers. This affects all webviews within the app!
|
||||||
engine.setPaused(false);
|
engine.setPaused(false);
|
||||||
this.pluginManager.onResume(keepRunning);
|
this.pluginManager.onResume(keepRunning);
|
||||||
|
// To be the same as other platforms, fire this event only when resumed after a "pause".
|
||||||
|
if (hasPausedEver) {
|
||||||
sendJavascriptEvent("resume");
|
sendJavascriptEvent("resume");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void handleStart() {
|
public void handleStart() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
|
@ -58,7 +58,7 @@ public class CordovaPluginTest extends BaseCordovaIntegrationTest {
|
|||||||
//currently only one of the cases is covered
|
//currently only one of the cases is covered
|
||||||
LifeCyclePlugin testPlugin = (LifeCyclePlugin)cordovaWebView.getPluginManager().getPlugin("LifeCycle");
|
LifeCyclePlugin testPlugin = (LifeCyclePlugin)cordovaWebView.getPluginManager().getPlugin("LifeCycle");
|
||||||
|
|
||||||
assertEquals("start,pause,stop,", testPlugin.calls);
|
assertEquals("start,resume,pause,stop,", testPlugin.calls);
|
||||||
testPlugin.calls = "";
|
testPlugin.calls = "";
|
||||||
// testOnStart
|
// testOnStart
|
||||||
invokeBlockingCallToLifeCycleEvent("callActivityOnStart");
|
invokeBlockingCallToLifeCycleEvent("callActivityOnStart");
|
||||||
|
Loading…
Reference in New Issue
Block a user