Android kills the process:
For the end of the process in the development of app application is still necessary, here sorted out three ways, we can choose according to the needs.
When the application is no longer in use, you usually need to close the application, you can use the following three ways to turn off the Android application:
The first method: Get the ID of the current process and then kill the process.
Android.os.Process.killProcess (Android.os.Process.myPid ())
Then practice:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http:// Schemas.android.com/tools "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_ Horizontal_margin "
android:paddingright=" @dimen/activity_horizontal_margin "
android:paddingtop=" @dimen /activity_vertical_margin "
tools:context=". Mainactivity ">
<button
android:layout_width=" wrap_content "
android:layout_height=" Wrap_ Content "
android:layout_centerhorizontal=" true "
android:layout_centervertical=" true "
android:o nclick= "click"
android:text= "Suicide"/>
</RelativeLayout>
Add Click event Code
public void Click {
//get id
int pid = Android.os.Process.myPid () for the current process;
This method can only be used for suicide operation
Android.os.Process.killProcess (PID);
}
Before clicking the button, you can see the process
After clicking the button, the process commits suicide
Second method: Terminates the currently running Java Virtual machine, causing the program to terminate
System.exit (0);
Android.permission.KILL_BACKGROUND_PROCESSES
The third method is to force the shutdown of everything associated with the package execution
Activitymanager manager = (Activitymanager) getsystemservice (context.activity_service);
Manager.restartpackage (Getpackagename ());
<uses-permission android:name= "Android.permission.RESTART_PACKAGES"/>
Thank you for reading, I hope to help you, thank you for your support for this site!