Question

How can I stop my whole App in simple terms? (all activities, services, Threads, etc. simply everything) The life-cycle callbacks (especially onStop() and onDestroy()) should be called.

Google suggests the following possible solution:

  • kill the process: but this wouldn't call the lifecycle callbacks
  • and finish(); but this is only for one Activity:

But is it possible to access this method from outside like:

//Getting all activityies, how?
//For each gotten activity
AcitvityName.finish();
or via or via getParent().finish(); ?

This did not help me: Best way to quit android app?

FD

Was it helpful?

Solution 2

Use a broadcast receiver to call all your activities and call finish locally in them, invoking the current lifecycle callbacks.

Broadcastreceiver and Paused activity

http://developer.android.com/reference/android/content/BroadcastReceiver.html

OTHER TIPS

 @Override 
public void onPause() {        

        if(isFinishing()){
//code to finish() all activitys threads etc.....
}            

    super.onPause();
} 

in onPause() you can check for isFinishing() and then if it is finishing it goes to onDestroy() so you can execute some code youd like

Android don't allows user close application directly. You may minimize it to background or directly killing process.

But if you want to call some callbacks and release any resources when user remove your application from screen - you may to do following:

Clearing activity stack in onDestroy method (or if you wish in onBackPressed, onHomePressed). It must calls onDestroy methods in all removing activities so you may release any extended resources in onDestroy method of activity which has links on it.

So when user exit from your application - it will remove his activities and release all resources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top