Android off app

Source: Internet
Author: User

I used to be system.exit (0);

Today I saw someone say that this method is not very good. This is the method in J2se, he mainly by terminating the Java virtual machine being executed. Causes the program to terminate.

The following methods are recommended:

1. Kill this process:

Android.os.Process.killProcess (Android.os.Process.myPid ());

2. Force closure of all activities related to the package (killing other processes):

Activitymanager manager = (Activitymanager) getsystemservice (Context.activity_service); Manager.killbackgroundprocesses ("package name");

Due to the killing of other processes, we need to increase the privileges:

<uses-permission android:name= "Android.permission.RESTART_PACKAGES"/>

The following two ways to kill the process can still receive service, such as push. I don't have a chance (I tested it and I can receive it).

I used to use the System.exit (0);

2014.7.2 MORE:

Today, I saw someone say System.exit (0); it's a better way to get the program to quit normally.

The Android.os.Process.killProcess (Android.os.Process.myPid ()) is forced garbage collection. I go like a.


Android off 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.