/**
* 杀死勾选进程的方法
*/
public
void
killAll(View view){
List<TaskInfoBean> killProcessList=
new
ArrayList<TaskInfoBean>();
long
saveMemory=0;
//释放空间计时器
for
(TaskInfoBean userTaskInfo :
userTaskInfos
) {
if
(userTaskInfo.isChecked()){
Log. i(
TAG
,
"杀死进程"
+userTaskInfo.getPackageName());
killProcessList.add(userTaskInfo);
//将被勾选的进程的 app进要杀死的集合中
am
.killBackgroundProcesses(userTaskInfo.getPackageName());
saveMemory=saveMemory+userTaskInfo.getMemorySize();
//杀死进程的内存大小之和
}
}
for
(TaskInfoBean sysTaskInfo :
sysTaskInfos
) {
if
(sysTaskInfo.isChecked()){
Log. i(
TAG
,
"杀死进程"
+sysTaskInfo.getPackageName());
killProcessList.add(sysTaskInfo);
//将被勾选的进程的 app装进要杀死的集合中
am
.killBackgroundProcesses(sysTaskInfo.getPackageName());
saveMemory=saveMemory+sysTaskInfo.getMemorySize();
//杀死进程的内存大小之和
}
}
//
更新界面
for
(TaskInfoBean taskInfoBean : killProcessList) {
if
(taskInfoBean.isUserTask()){
userTaskInfos
.remove(taskInfoBean);
}
else
{
sysTaskInfos
.remove(taskInfoBean);
}
}
Toast. makeText(getApplicationContext(),
"删除了"
+killProcessList.size()+
"个进程,释放了"
+Formatter.formatFileSize(getApplicationContext(),saveMemory)+
"空间"
, 0).show();
//更新最新可用内存空间
tv_process_count
.setText(
"正在运行进程:"
+(
processTotal
-killProcessList.size())+
"个"
);
tv_mem_info
.setText(
"可用/总内存:"
+Formatter.formatFileSize(
this
,
availMem
+saveMemory)+
"/"
+Formatter. formatFileSize(
this
,
totalMem
));
adapter
.notifyDataSetChanged();
//刷新界面
}