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 ) .
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.
A started service can use the startForeground(int, android. app. Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory.
An Android activity is one screen of the Android app's user interface. In that way an Android activity is very similar to windows in a desktop application. An Android app may contain one or more activities, meaning one or more screens.
The Service class is the base class for all services. When you extend this class, it's important to create a new thread in which the service can complete all of its work; the service uses your application's main thread by default, which can slow the performance of any activity that your application is running.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With