Classic method for exiting multiple activities in Android
1. Use the list collection method
Save the activity instance with a list and kill it one by one
Add similar code in oncreate method of each activity:
When it is necessary to exit the program, call:
SysApplication. getInstance(). exit();
In short, the reference of each activity is added to a global linked list through the singleton mode, and the system is called every time the program exits When exit (0), first call the finish method of the activity in the linked list
Advantages: simple implementation and clear logic
2. Use broadcasting
recommend!! So convenient!!
The basic logic is to define a BaseActivity, bind the broadcast in this Activity, and invoke finish () in the broadcast onReceive method. Then, all future activities inherit this activity, send broadcast when exiting, exit baseactivity, the parent activity exits, and the child activity definitely exits.
The code is as follows:
An activity instance:
This is called at the exit:
Advantages: convenient, convenient!! Just send a broadcast where you exit!!
This is my exit output:
The above is the classic method of exiting multiple activities in Android introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!