Skip to content

Commit 1004f3c

Browse files
committed
Fix NPE on configuration change
otto doesn't like to be registered twice (cherry picked from commit 6dfee2a)
1 parent c3938a6 commit 1004f3c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/src/main/java/de/stephanlindauer/criticalmaps/managers/LocationUpdateManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class LocationUpdateManager {
3737
private final PermissionCheckHandler permissionCheckHandler;
3838
private final App app;
3939
private boolean isUpdating = false;
40+
private boolean isEventBusRegistered = false;
4041

4142
private static final float LOCATION_REFRESH_DISTANCE = 20; //20 meters
4243
private static final long LOCATION_REFRESH_TIME = 12 * 1000; //12 seconds
@@ -160,7 +161,11 @@ public void initialize() {
160161
} else {
161162
setStatusEvent();
162163
}
163-
eventBus.register(this);
164+
165+
if(!isEventBusRegistered) {
166+
eventBus.register(this);
167+
isEventBusRegistered = true;
168+
}
164169

165170
// Short-circuit here: if no provider exists don't start listening
166171
if (noProviderExists) {
@@ -232,6 +237,7 @@ public void handleShutdown() {
232237
} catch (IllegalArgumentException ignored) {
233238
// nothing we can do
234239
}
240+
isEventBusRegistered = false;
235241
}
236242

237243
private void publishNewLocation(Location location) {

0 commit comments

Comments
 (0)