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

user420574
  • 1,437
  • 5
  • 21
  • 33
  • 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. – Cristian May 02 '11 at 20:25
  • 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. – user420574 May 02 '11 at 20:30
  • Perhaps [this](http://www.vintage-computer.com/vcforum/archive/index.php/t-5628.html) can provide some inspiration. – regularfry May 02 '11 at 20:37

2 Answers2

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

John Leehey
  • 22,052
  • 8
  • 61
  • 88
-1

onDestroy()

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

Mxyk
  • 10,678
  • 16
  • 57
  • 76
Mikonos
  • 161
  • 6
  • 14
    onDestroy() is not usually called when app has been killed. – Michal Nov 24 '13 at 15:42
  • 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. – Ariel Malka Jan 26 '17 at 16:10