Add property that lets a PhoneGap app continue to run when another Android app or activity is started.

This commit is contained in:
Bryce Curtis 2010-11-14 17:33:06 -06:00
parent 4fa1f40b44
commit b8b1ad8421

View File

@ -78,6 +78,7 @@ import com.phonegap.api.PhonegapActivity;
* super.setProperty("loadUrlTimeoutValue", 60000);
* super.setProperty("loadingDialog", "Wait,Loading Demo...");
* super.setProperty("errorUrl", "file:///android_asset/www/error.html");
* super.setProperty("keepRunning", false);
*
* Splash screens:
* There are 2 ways to display a splash screen.
@ -131,6 +132,11 @@ public class DroidGap extends PhonegapActivity {
// LoadUrl timeout value in msec (default of 20 sec)
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.
*
@ -271,6 +277,9 @@ public class DroidGap extends PhonegapActivity {
this.loadUrlTimeoutValue = timeout;
}
// If keepRunning
this.keepRunning = this.getProperty("keepRunning", true);
// If url specified, then load it
String url = this.getProperty("url", null);
if (url != null) {
@ -556,6 +565,9 @@ public class DroidGap extends PhonegapActivity {
protected void onPause() {
super.onPause();
// If app doesn't want to run in background
if (!this.keepRunning) {
// Forward to plugins
this.pluginManager.onPause();
@ -565,6 +577,7 @@ public class DroidGap extends PhonegapActivity {
// Pause JavaScript timers (including setInterval)
this.appView.pauseTimers();
}
}
@Override
/**
@ -573,6 +586,9 @@ public class DroidGap extends PhonegapActivity {
protected void onResume() {
super.onResume();
// If app doesn't want to run in background
if (!this.keepRunning) {
// Forward to plugins
this.pluginManager.onResume();
@ -582,6 +598,7 @@ public class DroidGap extends PhonegapActivity {
// Resume JavaScript timers (including setInterval)
this.appView.resumeTimers();
}
}
@Override
/**