Commit 286697d8 authored by Chris Scott's avatar Chris Scott

Fix bugs related to plugin life-cycle reported by LogicsSoftware. Fixes issue 62 & 61

parent 8889849b
...@@ -71,7 +71,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -71,7 +71,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
backgroundServiceIntent = new Intent(this.cordova.getActivity(), BackgroundGeolocationService.class); backgroundServiceIntent = new Intent(this.cordova.getActivity(), BackgroundGeolocationService.class);
// Register for events fired by our IntentService "LocationService" // Register for events fired by our IntentService "LocationService"
EventBus.getDefault().register(this);
} }
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
...@@ -110,8 +109,11 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -110,8 +109,11 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
} else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) { } else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) {
result = applyConfig(data); result = applyConfig(data);
// TODO reconfigure Service
if (result) { if (result) {
Bundle event = new Bundle();
event.putString("name", action);
event.putBoolean("request", true);
EventBus.getDefault().post(event);
callbackContext.success(); callbackContext.success();
} else { } else {
callbackContext.error("- Configuration error!"); callbackContext.error("- Configuration error!");
...@@ -185,10 +187,12 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -185,10 +187,12 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
editor.commit(); editor.commit();
if (isEnabled) { if (isEnabled) {
EventBus.getDefault().register(this);
if (!BackgroundGeolocationService.isInstanceCreated()) { if (!BackgroundGeolocationService.isInstanceCreated()) {
activity.startService(backgroundServiceIntent); activity.startService(backgroundServiceIntent);
} }
} else { } else {
EventBus.getDefault().unregister(this);
activity.stopService(backgroundServiceIntent); activity.stopService(backgroundServiceIntent);
} }
} }
...@@ -215,6 +219,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -215,6 +219,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if (config.has("locationUpdateInterval")) { if (config.has("locationUpdateInterval")) {
editor.putInt("locationUpdateInterval", config.getInt("locationUpdateInterval")); editor.putInt("locationUpdateInterval", config.getInt("locationUpdateInterval"));
} }
if (config.has("fastestLocationUpdateInterval")) {
editor.putInt("fastestLocationUpdateInterval", config.getInt("fastestLocationUpdateInterval"));
}
if (config.has("activityRecognitionInterval")) { if (config.has("activityRecognitionInterval")) {
editor.putLong("activityRecognitionInterval", config.getLong("activityRecognitionInterval")); editor.putLong("activityRecognitionInterval", config.getLong("activityRecognitionInterval"));
} }
...@@ -231,7 +238,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -231,7 +238,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
editor.putInt("stopAfterElapsedMinutes", config.getInt("stopAfterElapsedMinutes")); editor.putInt("stopAfterElapsedMinutes", config.getInt("stopAfterElapsedMinutes"));
} }
if (config.has("stopOnTerminate")) { if (config.has("stopOnTerminate")) {
editor.putBoolean("stopOnTerminate", config.getBoolean("stopOnTerminate")); stopOnTerminate = config.getBoolean("stopOnTerminate");
editor.putBoolean("stopOnTerminate", stopOnTerminate);
} }
if (config.has("startOnBoot")) { if (config.has("startOnBoot")) {
editor.putBoolean("startOnBoot", config.getBoolean("startOnBoot")); editor.putBoolean("startOnBoot", config.getBoolean("startOnBoot"));
...@@ -408,6 +416,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -408,6 +416,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
Activity activity = this.cordova.getActivity(); Activity activity = this.cordova.getActivity();
EventBus.getDefault().unregister(this);
SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0); SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("activityIsActive", false); editor.putBoolean("activityIsActive", false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment