我很困惑应用程序何时进入后台以及应用程序在后台运行时的含义。
我正在尝试使用长时间运行的服务来检测位置更改。
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);
}
}
我的问题是: