diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index eaef4449db..2bd72f178b 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -39,8 +39,6 @@ import info.nightscout.utils.LocaleHelper; public class MainActivity extends AppCompatActivity { private static Logger log = LoggerFactory.getLogger(MainActivity.class); - private static KeepAliveReceiver keepAliveReceiver; - static final int CASE_STORAGE = 0x1; static final int CASE_SMS = 0x2; @@ -77,11 +75,7 @@ public class MainActivity extends AppCompatActivity { // no action } - if (keepAliveReceiver == null) { - keepAliveReceiver = new KeepAliveReceiver(); - startService(new Intent(this, ExecutionService.class)); - keepAliveReceiver.setAlarm(this); - } + setUpTabs(false); } @@ -169,8 +163,7 @@ public class MainActivity extends AppCompatActivity { // break; case R.id.nav_exit: log.debug("Exiting"); - keepAliveReceiver.cancelAlarm(this); - + MainApp.instance().stopKeepAliveService(); MainApp.bus().post(new EventAppExit()); MainApp.closeDbHelper(); finish(); diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 505aecbaca..e76431e3df 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps; import android.app.Application; +import android.content.Intent; import android.content.res.Resources; import android.support.annotation.Nullable; @@ -37,11 +38,13 @@ import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment; import info.nightscout.androidaps.plugins.Wear.WearFragment; +import info.nightscout.androidaps.receivers.KeepAliveReceiver; import io.fabric.sdk.android.Fabric; public class MainApp extends Application { private static Logger log = LoggerFactory.getLogger(MainApp.class); + private static KeepAliveReceiver keepAliveReceiver; private static Bus sBus; private static MainApp sInstance; @@ -94,6 +97,26 @@ public class MainApp extends Application { MainApp.getConfigBuilder().initialize(); } MainApp.getConfigBuilder().uploadAppStart(); + + startKeepAliveService(); + } + + private void startKeepAliveService() { + if (keepAliveReceiver == null) { + keepAliveReceiver = new KeepAliveReceiver(); + if (Config.DANAR) { + startService(new Intent(this, info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService.class)); + startService(new Intent(this, info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService.class)); + } + keepAliveReceiver.setAlarm(this); + } + } + + + + public void stopKeepAliveService(){ + if(keepAliveReceiver!=null) + keepAliveReceiver.cancelAlarm(this); } public static Bus bus() { @@ -172,4 +195,4 @@ public class MainApp extends Application { super.onTerminate(); sDatabaseHelper.close(); } -} \ No newline at end of file +}