问题
I have a foreground monitoring class that registers as a LifecycleObserver
to the ProcessLifecycleOwner
's Lifecycle
. When I receive an ON_START
event, I am starting a Service
to run while the app is in the foreground. I am seeing IllegalStateException
s every so often on app launch stating that starting a service in the background is not allowed. Is this not a reliable way to check if the app is in the foreground? I thought ProcessLifecycleOwner
was suppose to be the answer to the old, hacky way of counting activities with Application.ActivityLifecycleCallbacks
. I didn't have this problem using that solution.
来源:https://stackoverflow.com/questions/55263146/crash-starting-service-when-observing-processlifecycleowner-on-start