Three ways to completely exit Android programs

Source: Internet
Author: User

1. Local methods for Dalvik VMS

Android.os.Process.killProcess (Android.os.Process.myPid ())//Get PID, currently get its own also only the API, otherwise from/PROC in its own enumeration of other processes it, but to illustrate that, Ending other processes does not necessarily have permissions, or it is a mess.
System.exit (0); Normal Java, C # Standard Exit method with a return value of 0 for graceful exit

2. Task Manager method

First of all to demonstrate that the method runs on Android 1.5 API level is more than 3 can, while the need for permission Android.permission.RESTART_PACKAGES, we directly end their package, Directly using the Activitymanager class's Restartpackage method, the parameter is package name, which is passed Getsystemservice (context.activity_service) To instantiate the Activitymanager object, which is provided by the system but needs to be displayed with declarative permissions, so it needs to be considered in a comprehensive way.

3. According to the activity's declaration cycle

We know that the Android window class provides a history stack, which we can skillfully implement using the stack principle, where we add the flag intent.flag_activity_clear_top directly to the intent when opening the b window in a window. When you turn on B, all activity for that process space will be cleared.

In the a window, use the following code to invoke the b window

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 directly using the Finish method to exit all.

Three ways to completely exit Android programs

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.