Saving the associated state of the service before it is deleted by Android

When the adroid service kills the OS (due to low memory or low power). Does the service mean a notification before it is killed? Is callback onDestroy () being called?

Our main concern is our ability to maintain a state of service until its death. We know that a service can be restarted by the system after resources are available, but what is the recommended way to preserve the state of a service until it is killed?

The attached sequence diagram of our understanding of the process of closing the power of a related service, it includes what we would like to do.

+4
source share
2 answers

Is the service notified before it is killed? Is callback onDestroy () being called?

Maybe. This is not guaranteed.

Our main concern is our ability to maintain a state of service until its death.

The service should not have a state that is presented only in RAM. You must maintain state when the state changes (for example, use a database).

+1
source

Starting with API level 14 (ICS), android os notifies the service if the service is deleted by the user, and also if the system decides that it is a good time for a process to trim unneeded memory from its process . Here is the link.

0
source

All Articles