onStartCommand服务流程后,与START_STICKY启动时被杀害被杀、启动时、流程、onStartCommand

2023-09-05 05:52:21 作者:逗比i

我一直在阅读了Android文档和我想知道如果任何人都可以提供一些线索上发生服务实例什么,当一个服务开始START_STICKY有它的过程中死亡。我假设本地状态数据(实例变量)也失去了。难道Android的做任何事情来帮助重新填充本地状态时,它再现了服务?

I have been reading the Android documentation and I am wondering if anyone can shed some light on what happens to a service instance when a service started with START_STICKY has it's process killed. I am assuming that the local state data (instance variables) are also lost. Does Android do anything to help re-populate the local state when it recreates the service?

我有一种被送到服务的意图一些数据。在onStateCommand(),我会基于什么是在故意填充该服务的实例数据。从我读了Android文档,意图传递给onStartCommand()将是空的时,该服务已被杀害并重新启动(与START_STICKY)。这是否意味着我失去了两个意图和服务的会员资料时,该服务被重建?

I had some data that was sent to the service in an intent. In onStateCommand(), I would populate the service's instance data based on what was in the intent. From what I have read in the Android docs, the intent passed to onStartCommand() will be null when the service has been killed and restarted (with START_STICKY). Does this mean that I lose both the intent and the service's member data when the service is recreated?

推荐答案

当一个进程被终止并重新创建,它会在整个生命周期中试(开始的onCreate)。这取决于它如何被打死,你如何保存数据也可能会或可能不会提供给你。

When a process is killed and recreated, it goes through the entire lifecycle again (starting at onCreate). Depending on how it was killed and how you save data it may or may not be available to you.

至于获得的意图后面,有一个标志START_REDELIVER_INTENT这将重新传递的意图。

As for getting the intent back, there's a flag for START_REDELIVER_INTENT that will redeliver the intent.