There is a problem in working through the program that requires a complete shutdown of the application, each with system.exit (0) or android.os.Process.killProcess ( Android.os.Process.myPid ()) These two methods, but I tried, system.exit (0) This is not at all, and android.os.Process.killProcess ( Android.os.Process.myPid ()) This can only close the current activity, that is, for an application that has only a single activity, if it is powerless for an application with more than one activity.
Let me introduce you to the full shutdown method for multiple activity applications:
1 /** 2 * The system perform a force stop of everything associated with3 * The given application package. All processes this share its UID4 * would be killed, all services it had running stopped, all activities5 * removed, etc. In addition, a {@linkintent#action_package_restarted}6 * Broadcast'll is sent, so, all of its registered alarms can * be stopped, notifications removed, etc.7 * 8 * must hold the permission * {@linkAndroid. Manifest.permission#restart_packages} to is able to9 * Call the This method.Ten * One * @paramPackageName The name of the stopped. A */ - Public voidrestartpackage (String packagename) { - Try { the Activitymanagernative.getdefault (). Restartpackage (PackageName); - } - Catch(RemoteException e) {} -}
So if you want to close the entire application, just run the following two lines of code:
1 This . Getsystemservice (activity_service); 2 activitymgr.restartpackage (Getpackagename ());
Now that we've made it halfway, what's half of it, that's what we always love to forget, let's look at the permission code :
1 < android:name= "Android.permission.RESTART_PACKAGES"/>
Reference Original: http://blog.163.com/yiba_suanzao/blog/static/130557377201131813952391/
"Android Note" Android completely shuts down the app