Three methods for completely exiting the Android program, android three methods
1. Local Dalvik VM Method
Android. OS. process. killProcess (android. OS. process. myPid () // obtain the PID. Currently, only this API is available for obtaining the PID. Otherwise, enumerate other processes from/proc, you may not have the permission to end other processes.
System. exit (0); // standard exit method of general java and c #. If the returned value is 0, the System Exits normally.
2. Task Manager Method
First, it must be noted that this method runs at the Android 1.5 API Level 3 or above, and the permission android. permission. RESTART_PACKAGES: You can directly end your package by using the restartPackage method of the ActivityManager class. The parameter is package name, which is passed through getSystemService (Context. ACTIVITY_SERVICE) to instantiate the ActivityManager object. This method is provided by the system, but the declared permissions need to be displayed.
3. According to the Activity declaration cycle
We know that the window class of Android provides A historical stack, and we can implement it skillfully through the stack principle. Here we add the Intent icon directly to window A when window A opens window B. FLAG_ACTIVITY_CLEAR_TOP. When B is enabled, all activities in the process space are cleared.
Use the following code to call window B in window:
Intent intent = new Intent ();
Intent. setClass (Android123.this, CWJ. class );
Intent. setFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP); // pay attention to the FLAG settings of the row.
StartActivity (intent );
Next, use the finish method to exit all the services in window B.