If you start a service by calling
startService()
then you have to callstopService()
orstopSelf()
to stop the service. If you want to stop a service after doing some work, you might want to useIntentService
instead.`
如果我没有使用IntentService
,那么如果我不调用stopService()
或stopSelf()
,服务何时停止方法?
最佳答案
If I am NOT using IntentService then when will service stop if I don't call stopService() or stopSelf() methods?
如果您的服务是通过 startService()
启动的,并且您没有调用 stopService()
或 stopSelf()
,您的服务将被视为“正在运行”,直到您的进程终止。作为此过程的一部分,您可能会或可能不会被调用 onDestroy()
,具体取决于您的进程的系统 RAM 的需求有多紧急。
如果从 onStartCommand()
返回 START_STICKY
或 START_REDELIVER_INTENT
,您的进程和服务应该会在某个时间自动重新启动在不久的将来,当 RAM 需要允许时。
关于android - 如果我不调用 stopService() 或 stopSelf() 方法,服务何时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35503886/