If your service is currently running and the system needs to kill its process (which should be fairly rare, only when for some reason resources are really right), just like activity you won't receive a call to onDestroy(), the process will just be killed.
If you want to have a queue of actions to perform that can survive the process dying, you will need to put them into persistent storage when they are created and then read them out and process them in your service. Note that the system bumps your process to foreground priority while calling a service's onCreate(), onStart(), and onDestroy() methods to facilitate this. For example a common pattern is to enqueue actions into a service with startService(), put the action into someplace safe in onStart(), and then pull them out as it is running. The is example called ServiceStartArgs in API demos showing the basics of this, though it doesn't include putting the actions in persistent storage. On Mar 27, 4:27 pm, severian <[EMAIL PROTECTED]> wrote: > I'm not sure how to preserve the state of the message queue between > instantiations of the application. > > To take the example of my app, I have a Service that starts a > background thread. It creates a Handler for that thread which is > subsequently used by Activities to post messages for background > processing. Now, what happens if Android decides to kill the process > while there are still messages in the queue? The onDestroy() method of > the Service seems like the right place to deal with this, by, say, > stopping the looper and the background thread, and then saving any > unprocessed messages into persistent storage, so that when the Service > is recreated it can prepopulate the queue with the saved messages. > > But looking at the API for Handler, Looper, and MessageQueue it's not > obvious how I can do this. What is the right way to save this state? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new M5 SDK! http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

