gpt4 book ai didi

android - 如何在奥利奥中启动后台服务?

转载 作者:行者123 更新时间:2023-11-29 16:35:41 24 4
gpt4 key购买 nike

oreo 版本之前,默认所有服务在后台使用 startService() 启动,但在 oreo 中启动服务有一些限制后台服务,我可以在 oreo 中使用 startService() 启动后台服务吗?

最佳答案

只要您的应用程序处于前台,您就可以使用 startService() ,如果您的应用程序进入后台并且您调用 startService() ,您将得到 IllegalStateException

或者你可以使用startForeground()来启动一个服务

来自文档

While an app is in the foreground, it can create and run both foreground and background services freely. When an app goes into the background, it has a window of several minutes in which it is still allowed to create and use services. At the end of that window, the app is considered to be idle. At this time, the system stops the app's background services, just as if the app had called the services' Service.stopSelf() methods

检查 Documentation了解更多信息

关于android - 如何在奥利奥中启动后台服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com