mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-22 07:14:54 +00:00
Fix crash when calling disable while not in the background
This commit is contained in:
parent
b2ec730c88
commit
379e9228fb
@ -43,6 +43,10 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
// Flag indicates if the plugin is enabled or disabled
|
// Flag indicates if the plugin is enabled or disabled
|
||||||
private boolean isDisabled = false;
|
private boolean isDisabled = false;
|
||||||
|
|
||||||
|
// Flag indicates if the service is bind
|
||||||
|
private boolean isBind = false;
|
||||||
|
|
||||||
|
|
||||||
// Settings for the notification
|
// Settings for the notification
|
||||||
static JSONObject settings = new JSONObject();
|
static JSONObject settings = new JSONObject();
|
||||||
|
|
||||||
@ -188,6 +192,8 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
intent, connection, Context.BIND_AUTO_CREATE);
|
intent, connection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
|
|
||||||
|
isBind = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,7 +206,12 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
Intent intent = new Intent(
|
Intent intent = new Intent(
|
||||||
context, ForegroundService.class);
|
context, ForegroundService.class);
|
||||||
|
|
||||||
|
if (isBind) {
|
||||||
context.unbindService(connection);
|
context.unbindService(connection);
|
||||||
|
}
|
||||||
|
|
||||||
context.stopService(intent);
|
context.stopService(intent);
|
||||||
|
|
||||||
|
isBind = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user