android: trying to start service again in case it was destroyed (#3745)
This commit is contained in:
parent
bd30b80e15
commit
f81e457e09
@ -197,10 +197,18 @@ class SimplexApp: Application(), LifecycleEventObserver {
|
|||||||
}
|
}
|
||||||
SimplexService.StartReceiver.toggleReceiver(mode == NotificationsMode.SERVICE)
|
SimplexService.StartReceiver.toggleReceiver(mode == NotificationsMode.SERVICE)
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
if (mode == NotificationsMode.SERVICE)
|
if (mode == NotificationsMode.SERVICE) {
|
||||||
SimplexService.start()
|
SimplexService.start()
|
||||||
else
|
// Sometimes, when we change modes fast from one to another, system destroys the service after start.
|
||||||
|
// We can wait a little and restart the service, and it will work in 100% of cases
|
||||||
|
delay(2000)
|
||||||
|
if (!SimplexService.isServiceStarted && appPrefs.notificationsMode.get() == NotificationsMode.SERVICE) {
|
||||||
|
Log.i(TAG, "Service tried to start but destroyed by system, repeating once more")
|
||||||
|
SimplexService.start()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
SimplexService.safeStopService()
|
SimplexService.safeStopService()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode != NotificationsMode.PERIODIC) {
|
if (mode != NotificationsMode.PERIODIC) {
|
||||||
|
@ -262,7 +262,7 @@ class SimplexService: Service() {
|
|||||||
private const val SHARED_PREFS_SERVICE_STATE = "SIMPLEX_SERVICE_STATE"
|
private const val SHARED_PREFS_SERVICE_STATE = "SIMPLEX_SERVICE_STATE"
|
||||||
private const val WORK_NAME_ONCE = "ServiceStartWorkerOnce"
|
private const val WORK_NAME_ONCE = "ServiceStartWorkerOnce"
|
||||||
|
|
||||||
private var isServiceStarted = false
|
var isServiceStarted = false
|
||||||
private var stopAfterStart = false
|
private var stopAfterStart = false
|
||||||
|
|
||||||
fun scheduleStart(context: Context) {
|
fun scheduleStart(context: Context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user