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

2

7

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

Enslave answered 2/5, 2011 at 20:20 Comment(3)
I hope there's no way to do so. If I use Advanced Task Killer to kill a process, what I would expect is that the process won't be alive again (unless I explicitly execute it). It will be annoying to have an imortal process.Nichollenicholls
I just want to know if the service is alive or not. I know that Advanced Task killer will kill the process but I have no way to detect that the service is killed because the onDestroy is not called.Enslave
Perhaps this can provide some inspiration.Lemon
M
2

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().

Mycah answered 2/5, 2011 at 20:37 Comment(0)
G
-2

onDestroy()

If you want to restart the service, you can restart in onDestroy().

Goodnight answered 2/7, 2012 at 7:17 Comment(2)
onDestroy() is not usually called when app has been killed.Contorted
According to a majority of responses on SO: onDestroy() is not called when a service is killed by the system. Besides, if you'd like to have your service restarted automatically, you'd use START_STICKY in the first place.Brahmani

© 2022 - 2024 — McMap. All rights reserved.