My app runs a geolocalisation service that the user can active or disactive by a toggleButton. To check the status of the service, I write a boolean in the Shared Preferences. I listen the beginning of the service and the end of it thanks to the onDestroy() of my service.
My problem is that: When the user kill the service with the "advanced task killer", I can't know that the service is killed, the onDestroy is not called !
How can I deal with that?
Thanks for your help.
Florent
When a process is killed (using ATK or android's own force stop button, or the function here), it is immediately purged from memory (if the kernel allows it). This means there's no chance for any additional code to run, meaning there is no way to really deal with a "force kill" sent to your application.
If you want to handle this, you have 2 options (that I can think of):
- Publish a disclaimer telling users to add your app to the "ignore" list of ATK.
- Find some way to maintain functionality without relying on the onDestroy() method.
EDIT:
If you want to check for your process from a list of currently-running processes, look into getRunningAppProcesses().
onDestroy()
If you want to restart the service, you can restart in onDestroy()
.
来源:https://stackoverflow.com/questions/5862045/can-i-detect-when-my-service-is-killed-by-advanced-task-killer