CB-8684 Add onStart/onStop hooks for plugins (close #173)

This commit is contained in:
Tony Homer
2015-04-08 15:00:38 -04:00
committed by Andrew Grieve
parent 581252febc
commit a652d892ca
8 changed files with 204 additions and 0 deletions
@@ -268,6 +268,34 @@ public class CordovaActivity extends Activity {
this.appView.handleResume(this.keepRunning);
}
/**
* Called when the activity is no longer visible to the user.
*/
@Override
protected void onStop() {
super.onStop();
LOG.d(TAG, "Stopped the activity.");
if (this.appView == null) {
return;
}
this.appView.handleStop();
}
/**
* Called when the activity is becoming visible to the user.
*/
@Override
protected void onStart() {
super.onStart();
LOG.d(TAG, "Started the activity.");
if (this.appView == null) {
return;
}
this.appView.handleStart();
}
/**
* The final call you receive before your activity is destroyed.
*/
@@ -148,6 +148,18 @@ public class CordovaPlugin {
public void onResume(boolean multitasking) {
}
/**
* Called when the activity is becoming visible to the user.
*/
public void onStart() {
}
/**
* Called when the activity is no longer visible to the user.
*/
public void onStop() {
}
/**
* Called when the activity receives a new intent.
*/
@@ -61,6 +61,10 @@ public interface CordovaWebView {
void handleResume(boolean keepRunning);
void handleStart();
void handleStop();
void handleDestroy();
/**
@@ -115,6 +115,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
pluginManager.addService(CoreAndroid.PLUGIN_NAME, "org.apache.cordova.CoreAndroid");
pluginManager.init();
}
@Override
@@ -446,6 +447,20 @@ public class CordovaWebViewImpl implements CordovaWebView {
this.pluginManager.onResume(keepRunning);
sendJavascriptEvent("resume");
}
@Override
public void handleStart() {
if (!isInitialized()) {
return;
}
pluginManager.onStart();
}
@Override
public void handleStop() {
if (!isInitialized()) {
return;
}
pluginManager.onStop();
}
@Override
public void handleDestroy() {
@@ -264,6 +264,28 @@ public class PluginManager {
}
}
/**
* Called when the activity is becoming visible to the user.
*/
public void onStart() {
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onStart();
}
}
}
/**
* Called when the activity is no longer visible to the user.
*/
public void onStop() {
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onStop();
}
}
}
/**
* The final call you receive before your activity is destroyed.
*/