Here is the code. The principle of this method is to use a list to record each start of the acitivity, at the exit time loop out of the list to save the acitivity, so that all the acitivity perfect exit.
Write a class inheritance firstApplication
PackageCom.Zhaoba.Service;import Java.. Arraylistimport Java.. List import Android.. Activityimport Android.. Application publicclassagentappextends application
{ privateList<activity> Activities =newArrayList<activity > ();
privatestaticAgentapp instance;
PrivateAgentapp() { } //Get unique application in Singleton mode
public static Agentapp getinstance()
{ if(null= =instance)
{ instance=newagentapp();
} return instance;
} //store activity into List
publicvoid addactivity(activity activity){ activities. Add(activity); }
@Override //Traverse activity that is stored in the list and exit
public void onterminate()
{super. (); for (activity Activity : Activities) { activity finish (); /span>
Android. Os. Process. KillProcess(android. Os. Process. Mypid()); }
}
Then add the following code to each of the OnCreate methods that you want to acitivity:
Agentapp. GetInstance(). Addactivity(this);
Finally, execute the following code in the interface you want to exit:
Agentapp. GetInstance(). Onterminate();
With just these three steps, you can pull out perfectly. Very practical
Full exit method with multiple activity in the Android program