Android: Force other apps to close

Source: Internet
Author: User

Force close other applications, you can use Activitymanager, first need to obtain (Activitymanager) Getsystemservice (Context.activity_service);

You can then call its function to close the operation, and there are two ways to do so:

1. void killbackgroundprocesses (String packagename): This method is described in the API of the Android website, after the kill, the closed application will be restarted.

The system immediately kill all background processes associated and the given package. The same as the kernel killing those processes to reclaim memory; The system would take care of restarting these processes in the future as needed.

Use: Requires permission: <uses-permission android:name= "Android.permission.KILL_BACKGROUND_PROCESSES"/>

2. void Forcestoppackage (String packagename): This method is not currently available on the Android website API, I do not know why ah ...

Use:

requires permission: android:shareduserid= "Android.uid.system"

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

Your own implementation of the Code:

Activitymanager Activitymanager = (Activitymanager) Getsystemservice (Context.activity_service); Activitymanager.forcestoppackage ("Com.android.scan");

It is recommended to use the 2nd type ...

Reference: http://blog.csdn.net/huxueyan521/article/details/8921976

http://blog.csdn.net/mingli198611/article/details/7057615

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.