This example implements the ability to turn off all activity when Android exits and share them for your reference. The specific methods are as follows:
In general, when Android exits, some activity may not be closed. To turn off all activity when Android exits, here are the following classes:
Class public class
closeactivityclass{public
static list<activity> activitylist = new for closing an activity Arraylist<activity> ();
public static void Exitclient (context ctx)
{
//Close all activity for
(int i = 0; i < activitylist.size (); i++) c7/>{
if (null!= activitylist.get (i))
{
activitylist.get (i). Finish ();
}
Activitymanager activitymgr = (activitymanager) ctx.getsystemservice (context.activity_service);
Activitymgr.restartpackage (Ctx.getpackagename ());
System.exit (0);
}
}
Then add one sentence to the OnCreate (Bundle savedinstancestate) method of each activity in the application:
CloseActivityClass.activityList.add (this);
When the application exits:
Closeactivityclass.exitclient (Mainactivity.this);
This allows all activity of the application to be completely shut down when the application is exited.
It is believed that this article has certain reference value to everyone's Android program design.