I'm confused about when an app goes in the background and what the implications are when an app goes in the background.
I'm trying to have a long running service that detects location changes.
Plugin.xml:
<service android:name="MyLocationService.java" />
MyLocationService.java
public MyLocationService extends Service implements LocationListener {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//arguments for requestUpdates defined elsewhere
this.locationManager.requestUpdates(minTimeBetweenUpdates, minDistanceBetweenUpdates, myCriteria, this, null);
}
public void onLocationChanged(Location location) {
if (/*rare condition*/) {
PluginResult result = new PluginResult(PluginResult.Status.OK, "We made it!");
result.setKeepCallback(true);
MyPlugin.callbackContext.sendPluginResult(result);
}
}
}
MyPlugin.java
public class MyPlugin extends CordovaPlugin {
public static CallbackContext callbackContext;
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity();
Intent myIntent = new Intent(activity, MyLocationService);
MyPlugin.callbackContext = callbackContext;
activity.startService(myIntent);
}
}
My questions are:
- When will the onLocationChanged stop receiving updates?
I know it'll stop receiving updates when I call locationManager.removeUpdates, but I wonder what other conditions will cause it to stop receiving updates...maybe when the app goes into the background? - When will I not be able to invoke the javascript callback via Cordova?
- Are there better ways to have a long running service that will "wake up the app" when necessary?