"Android Note" Android completely shuts down the app

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.