views:

55

answers:

1

Hi.

I just want to know how detect that the activity or service has been killed by the advanced task killer? I was expecting the onDestroy method to be called, but it doesnt!

My app starts the background service on boot. The activity is not started except from menu. But its name appears in the advanced task killer list. When I try to kill it, it doesnt call the onDestroy method neither the service's.

Any ideas?

Thanks in advance.

A: 

I just want to know how detect that the activity or service has been killed by the advanced task killer?

You do not receive any notification when your task is killed in this fashion.

I was expecting the onDestroy method to be called, but it doesnt!

There are various scenarios in which onDestroy() of an activity or service will not be called. This is one of them.

My app starts the background service on boot.

I sincerely hope that service shuts down in a few seconds. Otherwise, please consider whether what you are doing is the right thing.

CommonsWare
Actually the service doesnt do much work. It is just started so that when a call received, it starts doing stuff. It can be closed from the activity menu, but I just want to find a way to cleanup after the service is killed.
Doaa
Do you think it's better to start the service when a call is received then stop it again?
Doaa
@Doaa: "It is just started so that when a call received, it starts doing stuff." -- you can use a manifest-registered `BroadcastReceiver` for that, looking for `ACTION_PHONE_STATE_CHANGED`. "Do you think it's better to start the service when a call is received then stop it again?" -- yes. The less your service is in memory, the less likely it is to be a target of task killers.
CommonsWare