private void killAppProgress() {
try {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasks = am.getAppTasks();
if (tasks != null && tasks.size() > 0 ) {
tasks.get(0).setExcludeFromRecents(true);
}
List mList = am.getRunningAppProcesses();
for (Object runProgress : mList) {
if (((ActivityManager.RunningAppProcessInfo) runProgress).pid != android.os.Process.myPid()) {
android.os.Process.killProcess(((ActivityManager.RunningAppProcessInfo) runProgress).pid );
}
}
android.os.Process.killProcess(android.os.Process.myPid());
am.killBackgroundProcesses(getPackageName());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
或者 :
private void clearMore() {
int total = 0;
int memorySize = 0;
for (ProcessInfo infos : processInfoList) {
if (infos.isChecked()) {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
am.killBackgroundProcesses(infos.getPkgname());
total++;
memorySize += infos.getMemSize();
processInfoList.remove(infos);
break;
}
}
Toast.makeText(
this,
"清理了" + total + "个进程," + "释放了"
+ TrafficDataUtil.getMemoryData(memorySize) + "内存",
Toast.LENGTH_SHORT).show();
adapter=new ClearMemoryAdapter(this, processInfoList);
listView.setAdapter(adapter);
btn_clea.setText("一键清理");
}