From 9d686adf7ef89a85bc1231f0869cd7a1eef3cc74 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 31 Jul 2018 19:11:32 +0200 Subject: [PATCH] finish apllication after clicking Exit --- .../services/NSClientService.java | 2 -- .../Persistentnotification/DummyService.java | 27 +++++++++++++++++++ .../services/DanaRExecutionService.java | 2 -- .../services/DanaRKoreanExecutionService.java | 4 +-- .../PumpDanaRS/services/DanaRSService.java | 2 -- .../services/DanaRv2ExecutionService.java | 4 +-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index d7066705b9..a4f9956a5d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -161,8 +161,6 @@ public class NSClientService extends Service { destroy(); stopSelf(); - if (L.isEnabled(L.NSCLIENT)) - log.debug("EventAppExit finished"); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java index fad1147dfc..56b3a2cd09 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java @@ -6,10 +6,21 @@ import android.content.Intent; import android.os.IBinder; import android.support.annotation.Nullable; +import com.squareup.otto.Subscribe; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.logging.L; + /** * Keeps AndroidAPS in foreground state, so it won't be terminated by Android nor get restricted by the background execution limits */ public class DummyService extends Service { + private static Logger log = LoggerFactory.getLogger(L.CORE); + @Nullable @Override public IBinder onBind(Intent intent) { @@ -24,8 +35,24 @@ public class DummyService extends Service { return START_STICKY; } + @Subscribe + public void onStatusEvent(EventAppExit event) { + if (L.isEnabled(L.CORE)) + log.debug("EventAppExit received"); + + stopSelf(); + } + + @Override + public void onCreate() { + MainApp.bus().register(this); + } + @Override public void onDestroy() { + if (L.isEnabled(L.CORE)) + log.debug("onDestroy"); + MainApp.bus().unregister(this); stopForeground(true); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 446913b1b8..b1d8ec44bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -412,8 +412,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { MainApp.instance().getApplicationContext().unregisterReceiver(receiver); stopSelf(); - if (L.isEnabled(L.PUMP)) - log.debug("EventAppExit finished"); } public PumpEnactResult setUserOptions() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 4be6cee2c1..a52d5d1d1f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -93,9 +93,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { MainApp.instance().getApplicationContext().unregisterReceiver(receiver); stopSelf(); - if (L.isEnabled(L.PUMP)) - log.debug("EventAppExit finished"); - } + } @Subscribe public void onStatusEvent(final EventPreferenceChange pch) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 932c9c747e..b370ab5711 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -526,8 +526,6 @@ public class DanaRSService extends Service { log.debug("EventAppExit received"); stopSelf(); - if (L.isEnabled(L.PUMP)) - log.debug("EventAppExit finished"); } void waitForWholeMinute() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 1e1147c849..7dfa5aa1f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -112,9 +112,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.instance().getApplicationContext().unregisterReceiver(receiver); stopSelf(); - if (L.isEnabled(L.PUMP)) - log.debug("EventAppExit finished"); - } + } @Subscribe public void onStatusEvent(final EventPreferenceChange pch) {