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,7 +351,9 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
startTone("long_beep");
// set our stationaryLocation
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
private void cleanUp() {
instance = null;
EventBus.getDefault().unregister(this);
removeActivityUpdates();
removeLocationUpdates();
googleApiClient.disconnect();
if (googleApiClient != null && googleApiClient.isConnected()) {
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