"Do not recreate the service, unless there are pending intents to deliver." 是什么意思?
What does it mean "Do not recreate the service, unless there are pending intents to deliver."?
我处理服务和 return 代码:START_NOT_STICKY。我不想重新启动服务。
但是文档说 "Do not recreate the service, unless there are pending intents to deliver."
您能否举例说明导致重新启动服务的这些未决意图?
当你returnSTART_NOT_STICKY
时,这意味着:
如果 Android 终止托管您的 Service
的进程(如果它需要资源或者它认为您的 Service
没有这样做,它几乎可以随时执行此操作任何有用的东西),会发生以下情况:
如果你的进程被杀死 after onStartCommand()
被调用,但是 before onStartCommand()
完成后,Android 将重新启动您的 Service
并再次调用 onStartCommand()
,重新交付进程被杀死时正在处理的 Intent
如果您的进程在 onStartCommand()
完成后 被终止,Android 只会重新启动您的 Service
如果有您的 Service
正在等待 Intent
。在这种情况下,如果为您的 Service
调用了 startService()
的任何组件并且您的 Service
尚未完全处理该调用,则将存在未决 Intent
。这可能是这种情况,例如,如果一个名为 startService()
的组件在您的 Service
已死时。或者,如果一个名为 startService()
的组件在您的 Service
仍在 onStartCommand()
方法中(处理之前对 startService()
的调用),则可能会发生这种情况。
我处理服务和 return 代码:START_NOT_STICKY。我不想重新启动服务。
但是文档说 "Do not recreate the service, unless there are pending intents to deliver." 您能否举例说明导致重新启动服务的这些未决意图?
当你returnSTART_NOT_STICKY
时,这意味着:
如果 Android 终止托管您的 Service
的进程(如果它需要资源或者它认为您的 Service
没有这样做,它几乎可以随时执行此操作任何有用的东西),会发生以下情况:
如果你的进程被杀死 after
onStartCommand()
被调用,但是 beforeonStartCommand()
完成后,Android 将重新启动您的Service
并再次调用onStartCommand()
,重新交付进程被杀死时正在处理的Intent
如果您的进程在
onStartCommand()
完成后 被终止,Android 只会重新启动您的Service
如果有您的Service
正在等待Intent
。在这种情况下,如果为您的Service
调用了startService()
的任何组件并且您的Service
尚未完全处理该调用,则将存在未决Intent
。这可能是这种情况,例如,如果一个名为startService()
的组件在您的Service
已死时。或者,如果一个名为startService()
的组件在您的Service
仍在onStartCommand()
方法中(处理之前对startService()
的调用),则可能会发生这种情况。