Crash starting service when observing ProcessLifecycleOwner ON_START

那年仲夏 提交于 2019-12-13 16:13:09

问题


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 IllegalStateExceptions 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!