Commit 74592aa0 authored by Chris Scott's avatar Chris Scott

Add some sanity-detection logic to try and fix reported crashes

parent 6099e4b8
......@@ -123,7 +123,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
public int onStartCommand(Intent intent, int flags, int startId) {
instance = this;
EventBus.getDefault().register(this);
EventBus eventBus = EventBus.getDefault();
if (!eventBus.isRegistered(this)) {
eventBus.register(this);
}
// Load config settings
SharedPreferences settings = getSharedPreferences(TAG, 0);
......@@ -348,10 +351,12 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
startTone("long_beep");
// set our stationaryLocation
stationaryLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (stationaryLocation != null) {
EventBus.getDefault().post(new StationaryLocation(stationaryLocation));
}
}
}
}
/**
* Translates a number representing desired accuracy of GeoLocation system from set [0, 10, 100, 1000].
* 0: most aggressive, most accurate, worst battery drain
......@@ -579,10 +584,13 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
private void cleanUp() {
instance = null;
EventBus.getDefault().unregister(this);
if (googleApiClient != null && googleApiClient.isConnected()) {
removeActivityUpdates();
removeLocationUpdates();
googleApiClient.disconnect();
}
}
/**
* Convert a Location instance to JSONObject
......
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