From 6f17fbcb7ee5cc6ca405f51612ba1fd752fed703 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Fri, 16 Dec 2022 16:18:12 +0100 Subject: [PATCH] analysis service start fix --- .../thibault/aves/channel/calls/AnalysisHandler.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AnalysisHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AnalysisHandler.kt index 1b38997c6..f0f020287 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AnalysisHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AnalysisHandler.kt @@ -9,8 +9,6 @@ import android.content.ServiceConnection import android.os.Build import android.os.IBinder import android.util.Log -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.ProcessLifecycleOwner import deckers.thibault.aves.AnalysisService import deckers.thibault.aves.AnalysisServiceBinder import deckers.thibault.aves.AnalysisServiceListener @@ -65,11 +63,9 @@ class AnalysisHandler(private val activity: Activity, private val onAnalysisComp .putExtra(AnalysisService.KEY_ENTRY_IDS, entryIds?.toIntArray()) .putExtra(AnalysisService.KEY_FORCE, force) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val appState = ProcessLifecycleOwner.get().lifecycle.currentState - if (!appState.isAtLeast(Lifecycle.State.STARTED)) { - result.error("startAnalysis-background", "cannot start foreground service from background", null) - return - } + // Foreground services cannot start from background, but the service here may start fine + // while the current lifecycle state (via `ProcessLifecycleOwner.get().lifecycle.currentState`) + // is only `INITIALIZED`, so we should not preemptively return when the state is below `STARTED`. activity.startForegroundService(intent) } else { activity.startService(intent)