根据文档,Android O 服务将在应用程序不再处于前台后几分钟停止。
该文档建议大多数服务可以替换为 JobScheduler 作业。我的问题是 - 工作是否也有任何特殊行为,或者它们的行为与 Android O 之前的服务相同?他们可以“永远”活着(当然,只要系统不需要内存),还是系统也会在某个窗口结束时杀死他们?
根据文档,Android O 服务将在应用程序不再处于前台后几分钟停止。
该文档建议大多数服务可以替换为 JobScheduler 作业。我的问题是 - 工作是否也有任何特殊行为,或者它们的行为与 Android O 之前的服务相同?他们可以“永远”活着(当然,只要系统不需要内存),还是系统也会在某个窗口结束时杀死他们?
Can they live "forever" (as long as the system doesn't need the memory, of course), or do the system also kills them off at the end of a certain window?
No. In my testing, you have ~10 minutes, as opposed to the ~1 minute for a regular service.
If you need a service that runs forever, you will need to make it be a foreground service (startForegroundService()
on Android O+, or startService()
plus startForeground()
on Android 7.1 and earlier).