On the complete exit of the Android program, there are a lot of posts on the Internet, there are many ways. Remember at that time I wrote the first relatively complete project when the problem, because of the activity of the life cycle is not enough to understand, but also use the tabactivity to make the hierarchical relationship is more complex, added in the program "Exit" menu items often can not completely exit, after the various search on the Internet, Various methods have tried, what system.exit (0) Ah, the end of the process, such as Ah, are still ineffective.
This method is discovered later. The idea is also very simple, think back to the original in order to solve this problem when the hard search, then decided to share it for people who encounter this problem as a reference.
Wordy enough, on the train of thought: Add a global variable as a program exit token (Boolean type), when you need to exit the program to True, in the program in each activity in the OnStart method to judge the variable, to true end itself.
Use Application to save a global variable isprogramexit. (for application use unfamiliar words to view relevant information)
Copy Code code as follows:
public class MyApplication Extendsapplication {
Program Exit Tag
private static Boolean isprogramexit = false;
public void Setexit (Booleanexit) {
Isprogramexit= exit;
}
Public Booleanisexit () {
return isprogramexit;
}
}
The OnStart method for each activity that needs to end when you exit adds the following code:
Copy Code code as follows:
Protected Voidonstart () {
Super.onstart ();
MyApplication mApp = (myapplication) getapplication ();
if (Mapp.isexit ()) {
Finish ();
}
}
So C ends up on its own, followed by a process that goes back to B, and then B is judged, because the exit condition satisfies, ends itself, and then goes back to a, also ends ...
As you can see, this approach is not clever or even complicated, because you have to add judgment to the onstart of each activity. But it is undeniable that this method is absolutely effective, regardless of your program in how the activity jumps to jump to go, as long as the command, all end, tried.
Therefore, have encountered the program exits the question friend may serve as the reference.