tags:

views:

33

answers:

1

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?

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_STYICKY). Does this mean that I lose both the intent and the service's member data when the service is recreated?

A: 

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.

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

Falmarri
Thanks for confirming my suspicions. I did not know about START_REDLIVER_INTENT (must have glossed over that part of the docs).
adstro