diff --git a/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java b/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java index a3a8ff25..7020a36c 100644 --- a/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +++ b/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java @@ -410,13 +410,17 @@ public BackgroundLocation getCurrentLocation(int timeout, long maximumAge, boole public void switchMode(final int mode) { synchronized (mLock) { - mService.executeProviderCommand(LocationProvider.CMD_SWITCH_MODE, mode); + if (mService != null) { + mService.executeProviderCommand(LocationProvider.CMD_SWITCH_MODE, mode); + } } } public void sendCommand(final int commandId) { synchronized (mLock) { - mService.executeProviderCommand(commandId, 0); + if (mService != null) { + mService.executeProviderCommand(commandId, 0); + } } } @@ -519,14 +523,18 @@ public void registerHeadlessTask(final String jsFunction) { private void startBackgroundService() { logger.info("Attempt to start bg service"); synchronized (mLock) { - mService.start(); + if (mService != null) { + mService.start(); + } } } private void stopBackgroundService() { logger.info("Attempt to stop bg service"); synchronized (mLock) { - mService.stop(); + if (mService != null) { + mService.stop(); + } } }