Reputation: 808
If an app is forced stop by following the steps Settings->Application->ManageApplications -> --> Force Stop , Does android call the onDestroy of the Activity or the Application ? (If not , Is there any way to know if the application has died due to a force Stop triggered by the User ) .
Upvotes: 8
Views: 15544
Reputation: 83303
Force stopping the app will kill the entire process (i.e. with Process.killProcess(int pid)
). All resources associated with the application will be removed and freed by the kernel. So no, there is no way that you can intercept this action.
When you release your application on the market, the developer console will provide you with stats regarding force closes, crashes, etc. (if that is why you are asking).
Upvotes: 14
Reputation: 10698
In short, no, onDestroy()
is not called, and you can't do this. Android doesn't support it.
A more extended answer...
onDestroy()
does not appear to be called in this scenario. I tested this by attempting to have it Toast
me before calling super.onDestroy, but the Toast
message never showed up. (And according to this post, onDestroy()
is really unreliable and won't be called often, if at all, on phones, whereas it may be called on an emulator - so be aware of that). Instead killProcess()
is called, and we cannot intercept that.
In addition, according to the accepted answer in this post, it appears we can't even catch and perform tasks after a user-controlled force stop.
Upvotes: 5
Reputation: 48559
No. This isn't really possible. I haven't looked at the Android code in question, but I would imagine that "force stop" is just calling kill
on the process ID of your app. So the only way you could intercept that is if you could trap signals, which I don't think Android allows.
If you were rooted, you could possibly do this, but not in any standard way.
Upvotes: 0