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 ...@@ -123,7 +123,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
instance = this; instance = this;
EventBus.getDefault().register(this); EventBus eventBus = EventBus.getDefault();
if (!eventBus.isRegistered(this)) {
eventBus.register(this);
}
// Load config settings // Load config settings
SharedPreferences settings = getSharedPreferences(TAG, 0); SharedPreferences settings = getSharedPreferences(TAG, 0);
...@@ -348,7 +351,9 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -348,7 +351,9 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
startTone("long_beep"); startTone("long_beep");
// set our stationaryLocation // set our stationaryLocation
stationaryLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); stationaryLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
EventBus.getDefault().post(new StationaryLocation(stationaryLocation)); if (stationaryLocation != null) {
EventBus.getDefault().post(new StationaryLocation(stationaryLocation));
}
} }
} }
} }
...@@ -579,9 +584,12 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -579,9 +584,12 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
private void cleanUp() { private void cleanUp() {
instance = null; instance = null;
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
removeActivityUpdates();
removeLocationUpdates(); if (googleApiClient != null && googleApiClient.isConnected()) {
googleApiClient.disconnect(); removeActivityUpdates();
removeLocationUpdates();
googleApiClient.disconnect();
}
} }
/** /**
......
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