RecentApp
systemUI/src/com/android/systemui/recents/RecentsActivity.java
RecentsView.java就是显示的控件
/**Dismisses the focused task. */
publicvoiddismissFocusedTask(){
//Get the first stack view
intchildCount = getChildCount();
for(inti = 0; i < childCount; i++) {
Viewchild = getChildAt(i);
if(child != mSearchBar){
TaskStackViewstackView = (TaskStackView) child;
stackView.dismissFocusedTask();
break;
}
}
}
自己写的,结束所有任务。直接用TaskStack做,不要用它自带的dismissFocusedTask来做,会超时,如果在线程里做又不能操作UI。
这里循环要注意,不要用正常的循环,否则会数组越界。因为做了removeTask后,数组内容会减少,所有每次只删除头上的task。
publicvoiddismissAllTask() {
Log.i("t","begin");
intnumStacks=mStacks.size();
Log.i("t","TaskStacksize "+numStacks);
for(inti = 0; i < numStacks; i++) {
TaskStacktaskStack=mStacks.get(i);
intnumStack=taskStack.getTaskCount();
Log.i("t","Tasksize "+numStack);
while(numStack>0){
Log.i("t","while===========");
//Ifdo removeTask(), the TaskStack will remove the task right
//now,so we must remove first task every time.
Taskt=taskStack.getTasks().get(0);
taskStack.removeTask(t);
numStack=taskStack.getTaskCount();
Log.i("t","Tasksize "+numStack);
Log.i("t","==============");
}
TaskStackView.java
/**Dismisses the focused task. */
publicvoiddismissFocusedTask(){
//Return early if there is no focused task index
if(mFocusedTaskIndex< 0) return;
Taskt = mStack.getTasks().get(mFocusedTaskIndex);
TaskViewtv = getChildViewForTask(t);
tv.dismissTask();
}