Service: do not crash on service restart after reboot

google-maps-v2
Georg Lukas 2020-08-28 20:23:32 +02:00
rodzic 93059b2426
commit 0cc40f7f10
1 zmienionych plików z 8 dodań i 2 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
package org.aprsdroid.app
import android.content.{BroadcastReceiver, Context, Intent}
import android.os.Build
class SystemEventReceiver extends BroadcastReceiver {
val TAG = "APRSdroid.SystemEventReceiver"
@ -8,7 +9,12 @@ class SystemEventReceiver extends BroadcastReceiver {
override def onReceive(ctx : Context, i : Intent) {
android.util.Log.d(TAG, "onReceive: " + i)
val prefs = new PrefsWrapper(ctx)
if (prefs.getBoolean("service_running", false))
ctx.startService(AprsService.intent(ctx, AprsService.SERVICE))
if (prefs.getBoolean("service_running", false)) {
val i = AprsService.intent(ctx, AprsService.SERVICE)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
ctx.startForegroundService(i)
else
ctx.startService(i)
}
}
}