Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android force Stop callback to application?

Tags:

java

android

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

like image 431
Chris Avatar asked Jun 22 '12 17:06

Chris


People also ask

How do I turn off callback on Android?

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.

What is startForeground in Android?

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.

What is activity Android?

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.

What is a service class Android?

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.


2 Answers

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

like image 186
Alex Lockwood Avatar answered Oct 18 '22 16:10

Alex Lockwood


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.

like image 34
Mxyk Avatar answered Oct 18 '22 14:10

Mxyk