Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detect when my service is killed by "Advanced Task Killer"

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

like image 932
user420574 Avatar asked May 02 '11 20:05

user420574


1 Answers

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):

  1. Publish a disclaimer telling users to add your app to the "ignore" list of ATK.
  2. 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().

like image 76
John Leehey Avatar answered Oct 05 '22 10:10

John Leehey