RecentsView 不显示已经结束的进程
方式1:不完善,如果批量kill掉应用会有些延迟
Index: quickstep/src/com/android/quickstep/views/RecentsView.java
===================================================================
@@ -209,6 +209,7 @@
import java.util.Objects;
import java.util.function.Consumer;
import android.util.Log;
+import android.app.ActivityManager;
/**
* A list of recent tasks.
@@ -1568,6 +1569,37 @@
return super.isPageScrollsInitialized() && mLoadPlanEverApplied;
}
+ /**
+ * 移除已经结束进程的task
+ */
+ private void removeRunningTask() {//ArrayList<GroupTask> taskGroups
+ ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
+ if (tasks !=null){
+ if (DEBUG) Log.d("RecentsView","mCtx tasks size="+tasks.size());
+ for (int i=0;i<tasks.size();i++){
+ ActivityManager.RecentTaskInfo task=tasks.get(i);
+ if (DEBUG) Log.d("RecentsView","removeTask taskId="+task.taskId +",isRunning="+task.isRunning);
+ if (DEBUG && task.baseIntent !=null && task.baseIntent.getComponent() !=null) Log.d("RecentsView","removeTask baseIntent="+task.baseIntent.getComponent().getPackageName());
+ if (!task.isRunning){
+ ActivityManagerWrapper.getInstance().removeTask(task.taskId);
+ }
+ }
+ }
+ }
protected void applyLoadPlan(ArrayList<GroupTask> taskGroups) {
if (mPendingAnimation != null) {
mPendingAnimation.addEndListener(success -> applyLoadPlan(taskGroups));
@@ -2336,6 +2368,8 @@
* Reloads the view if anything in recents changed.
*/
public void reloadIfNeeded() {
+ if (DEBUG) Log.d("RecentsView","reloadIfNeeded");
+ removeRunningTask();
if (!mModel.isTaskListValid(mTaskListChangeId)) {
mTaskListChangeId = mModel.getTasks(this::applyLoadPlan, RecentsFilterState
.getFilter(mFilterState.getPackageNameToFilter()));
网友评论