mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Add property that lets a PhoneGap app continue to run when another Android app or activity is started.
This commit is contained in:
parent
4fa1f40b44
commit
b8b1ad8421
@ -78,6 +78,7 @@ import com.phonegap.api.PhonegapActivity;
|
|||||||
* super.setProperty("loadUrlTimeoutValue", 60000);
|
* super.setProperty("loadUrlTimeoutValue", 60000);
|
||||||
* super.setProperty("loadingDialog", "Wait,Loading Demo...");
|
* super.setProperty("loadingDialog", "Wait,Loading Demo...");
|
||||||
* super.setProperty("errorUrl", "file:///android_asset/www/error.html");
|
* super.setProperty("errorUrl", "file:///android_asset/www/error.html");
|
||||||
|
* super.setProperty("keepRunning", false);
|
||||||
*
|
*
|
||||||
* Splash screens:
|
* Splash screens:
|
||||||
* There are 2 ways to display a splash screen.
|
* There are 2 ways to display a splash screen.
|
||||||
@ -130,6 +131,11 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
|
|
||||||
// LoadUrl timeout value in msec (default of 20 sec)
|
// LoadUrl timeout value in msec (default of 20 sec)
|
||||||
protected int loadUrlTimeoutValue = 20000;
|
protected int loadUrlTimeoutValue = 20000;
|
||||||
|
|
||||||
|
// Keep app running when pause is received. (default = true)
|
||||||
|
// If true, then the JavaScript and native code continue to run in the background
|
||||||
|
// when another application (activity) is started.
|
||||||
|
protected boolean keepRunning = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
@ -270,6 +276,9 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
this.loadUrlTimeoutValue = timeout;
|
this.loadUrlTimeoutValue = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If keepRunning
|
||||||
|
this.keepRunning = this.getProperty("keepRunning", true);
|
||||||
|
|
||||||
// If url specified, then load it
|
// If url specified, then load it
|
||||||
String url = this.getProperty("url", null);
|
String url = this.getProperty("url", null);
|
||||||
@ -555,15 +564,19 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
// If app doesn't want to run in background
|
||||||
|
if (!this.keepRunning) {
|
||||||
|
|
||||||
|
// Forward to plugins
|
||||||
|
this.pluginManager.onPause();
|
||||||
|
|
||||||
// Forward to plugins
|
// Send pause event to JavaScript
|
||||||
this.pluginManager.onPause();
|
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
||||||
|
|
||||||
// Send pause event to JavaScript
|
// Pause JavaScript timers (including setInterval)
|
||||||
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
this.appView.pauseTimers();
|
||||||
|
}
|
||||||
// Pause JavaScript timers (including setInterval)
|
|
||||||
this.appView.pauseTimers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -573,14 +586,18 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
// Forward to plugins
|
// If app doesn't want to run in background
|
||||||
this.pluginManager.onResume();
|
if (!this.keepRunning) {
|
||||||
|
|
||||||
// Send resume event to JavaScript
|
// Forward to plugins
|
||||||
this.appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
this.pluginManager.onResume();
|
||||||
|
|
||||||
// Resume JavaScript timers (including setInterval)
|
// Send resume event to JavaScript
|
||||||
this.appView.resumeTimers();
|
this.appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
||||||
|
|
||||||
|
// Resume JavaScript timers (including setInterval)
|
||||||
|
this.appView.resumeTimers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user