Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop an app by calling the lifecycle callbacks

Tags:

android

quit

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

like image 331
felixd Avatar asked Oct 04 '22 12:10

felixd


2 Answers

 @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

like image 87
JRowan Avatar answered Oct 13 '22 07:10

JRowan


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

like image 24
Sunkas Avatar answered Oct 13 '22 05:10

Sunkas