START_REDELIVER_INTENT 如何处理多个 Intent?

How does START_REDELIVER_INTENT behave with multiple Intents?

如果一个服务使用不同的 Intent 多次调用 startService(),当应用程序因内存不足而被杀死后重新启动时,它与 START_REDELIVER_INTENT 的行为如何?

示例:我用不同的 Intents 调用了三次 startService(intent, class)。在服务自行停止之前,OS 由于内存使用而终止应用程序或服务。后来,服务returns。根据 START_REDELIVER_INTENT onStartCommand() 应该使用启动它的原始 Intent 来调用。这三个都会被调用吗?只有第一个?只有最后一个?

我考虑过对其进行测试,但我想知道应该发生什么,而不仅仅是我的特定设备的功能。谢谢!

Will it be called for all three? Only the first one? Only the last one?

只有最后一个

documentation 对此非常清楚:

...如果此服务的进程在启动时被终止(从 onStartCommand() 返回后),那么它将被安排重新启动和最后交付的 Intent re-delivered 到 再次通过 onStartCommand().

采纳的答案不正确。

他没看到后面几个字:

This Intent will remain scheduled for redelivery until the service calls {@link #stopSelf(int)} with the start ID provided to {@link #onStartCommand}

意思是当一个intent来了,onStartCommand调用了,如果我们不stopSelf这个intent关联的onStartCommand的startId,系统会把这个intent当作not-handled, 那么当服务重新创建时,这些 not-handled 意图将重新交付给 onStartCommand.

所以,它会被调用3次。