diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index df26fc158..8f756b4ba 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -77,20 +77,13 @@ public class GBApplication extends Application { } }; private static DeviceManager deviceManager; - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - switch (action) { - case ACTION_QUIT: - quit(); - break; - } - } - }; - private void quit() { - GB.removeAllNotifications(this); + public static void quit() { + GB.log("Quitting Gadgetbridge...", GB.INFO, null); + Intent quitIntent = new Intent(GBApplication.ACTION_QUIT); + LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent); + GBApplication.deviceService().quit(); + GB.removeAllNotifications(context); } public GBApplication() { @@ -130,10 +123,6 @@ public class GBApplication extends Application { // mActivityDatabaseHandler = new ActivityDatabaseHandler(context); loadBlackList(); - IntentFilter filterLocal = new IntentFilter(); - filterLocal.addAction(ACTION_QUIT); - LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal); - if (isRunningMarshmallowOrLater()) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java index 73fd863c8..ea13096ca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java @@ -311,10 +311,7 @@ public class ControlCenter extends GBActivity { startActivity(debugIntent); return true; case R.id.action_quit: - GBApplication.deviceService().quit(); - - Intent quitIntent = new Intent(GBApplication.ACTION_QUIT); - LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent); + GBApplication.quit(); return true; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java index 08a11ad8c..0e639733f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java @@ -28,11 +28,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver { GBApplication.deviceService().connect(); } else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) { - GBApplication.deviceService().quit(); - - Intent quitIntent = new Intent(GBApplication.ACTION_QUIT); - - LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent); + GBApplication.quit(); } } }