简体   繁体   中英

Kill the applications running in background in android

I am trying to kill the background running applications using my application, but i unable to kill the process.

android.os.Process.killProcess(pid);
android.os.Process.sendSignal(pid,
android.os.Process.SIGNAL_KILL);
manager.killBackgroundProcesses(pid);

here pid is background running process id.

Every Android app has its own user id, group id, and most of the time runs within its own process. So your app probably have no privilege to kill other process.

There is obviously a design flaw, you'd be better state out what actually you want to do.

Use this killBackgroundProcesses:

   try {
            ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
            actvityManager.killBackgroundProcesses(pkgn.toString());// pkgn is a process id /////
        } catch (Exception e) {
            e.printStackTrace();
        }

您还必须在清单中添加它

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM