Android system off app

Source: Internet
Author: User

1. Overview:There are five priorities for application deployment to a mobile phone: foreground process, visual process, service process, background process, empty process. Android, by default, will not kill the process, the purpose of this practice is: to open the application again when you can quickly start, save time. But this also brings a problem, there are many applications in the background to leave an empty process, which will occupy some memory space, affecting the speed of the phone. as a responsible programmer, we want to make sure that the application releases the corresponding process at the end.
2. Closing modeFirst: Get the ID of the current process first, and then kill the thread.
  Gets the ID of the current process     int pid = Android.os.Process.myPid ();     This method can only be used for suicide operation     Android.os.Process.killProcess (PID);

The second type: terminates the currently running Java Virtual machine, causing the program to stop.
<span style= "White-space:pre" ></span>system.exit (0);

The third type: forces all executions that are associated with the package to be closed.
Activitymanager am = (activitymanager) getsystemservice (activity_service);     Am.killbackgroundprocesses (Getpackagename ());
The third need to add permissions:
<uses-permission android:name= "Android.permission.KILL_BACKGROUND_PROCESSES"/>







Android system off app

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.