简体   繁体   English

我正在搜索用于清除后台运行应用的代码,并从最近的应用菜单中删除所有其他应用

[英]I am searching a code for clearing background running apps and remove all other apps from recent apps menu

I tried a code but not able to remove app from recent app menu 我尝试了代码,但无法从最近的应用菜单中删除应用

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)
am.killBackgroundProcesses("com.example.admin.personalassistant");

You need this two permissions 您需要这两个权限

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

and then declare the ActivityManager and a List for the processes: 然后为进程声明ActivityManager和List:

ActivityManager am;    
List<ActivityManager.RunningAppProcessInfo> processes;

Use ActivityManager to list all process 使用ActivityManager列出所有进程

am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

and list all processes 并列出所有进程

processes = am.getRunningAppProcesses();

You can kill now all processes with a for-loop like this: 您现在可以使用for循环杀死所有进程,如下所示:

 for (ActivityManager.RunningAppProcessInfo processInfo: processes) {
                    android.os.Process.killProcess(processInfo.pid);
                    android.os.Process.sendSignal(processInfo.pid, android.os.Process.SIGNAL_KILL);
                    amg.killBackgroundProcesses(processInfo.processName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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