From 379e9228fbbf62f4c103c0ec4a1d83fc2a39b6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 7 Nov 2014 18:55:24 +0000 Subject: [PATCH] Fix crash when calling disable while not in the background --- src/android/BackgroundMode.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/android/BackgroundMode.java b/src/android/BackgroundMode.java index ea44045..464e29e 100644 --- a/src/android/BackgroundMode.java +++ b/src/android/BackgroundMode.java @@ -43,6 +43,10 @@ public class BackgroundMode extends CordovaPlugin { // Flag indicates if the plugin is enabled or disabled private boolean isDisabled = false; + // Flag indicates if the service is bind + private boolean isBind = false; + + // Settings for the notification static JSONObject settings = new JSONObject(); @@ -188,6 +192,8 @@ public class BackgroundMode extends CordovaPlugin { intent, connection, Context.BIND_AUTO_CREATE); context.startService(intent); + + isBind = true; } /** @@ -200,7 +206,12 @@ public class BackgroundMode extends CordovaPlugin { Intent intent = new Intent( context, ForegroundService.class); - context.unbindService(connection); + if (isBind) { + context.unbindService(connection); + } + context.stopService(intent); + + isBind = false; } }