1. Local method of Dalvik VM
Copy Code code as follows:
Android.os.Process.killProcess (Android.os.Process.myPid ())//Get PID
System.exit (0); Normal Java, C # Standard Exit method, the return value of 0 represents a graceful exit
2. Task Manager Method
The first thing to say is that the method runs at more than 3 of the Android 1.5 API level, and requires permissions
Activitymanager am = (activitymanager) getsystemservice (Context.activity_service);
Am.restartpackage (Getpackagename ());
The system will, under the package, all processes, services, all killed, you can kill clean, you should pay attention to add
<uses-permission android:name=\ "Android.permission.restart_packages\" ></uses-permission>
3. According to the statement cycle of the activity
We know that the Android window class provides a history stack, and we can do this by using the stack principle, where we add the flag intent.flag_activity_clear_top directly to the Intent when we open the B window in window A. By opening B, all activity in the process space will be cleared.
Use the following code in window A to invoke the b window
Copy Code code as follows:
Intent Intent = new Intent ();
Intent.setclass (Android123.this, Cwj.class);
Intent.setflags (Intent.flag_activity_clear_top); Note the flag setting of the bank
StartActivity (Intent);
Next in the b window you need to exit the direct use of the finish method to exit all.
4. Customize a actiivty stack, the same as above, but using a single case mode of the activity stack to manage all activity. and provide a way to quit all activity. The code is as follows:
public class Screenmanager {private static stack<activity> activitystack;
private static Screenmanager instance; Private Screenmanager () {} public static Screenmanager Getscreenmanager () {if (instance==null) {instance=new Screenman
Ager ();
return instance;
}//exit stack top activity public void popactivity (activity activity) {if (activity!=null) {activity.finish ();
Activitystack.remove (activity);
Activity=null;
}///get current stack top activity currentactivity () {activity activity=activitystack.lastelement ();
return activity; ///Push the current activity into the stack public void pushactivity (active activity) {if (activitystack==null) {activitystack=new stack<
Activity> ();
} activitystack.add (activity);
//Exits all activity in the stack public void Popallactivityexceptone (Class cls) {while (true) {The Activity activity=currentactivity ();
if (activity==null) {break;
} if (Activity.getclass (). Equals (CLS)) {break;
} popactivity (activity); }
}
}