美文网首页
RecentsView 不显示已经结束的进程

RecentsView 不显示已经结束的进程

作者: gale_小米 | 来源:发表于2024-09-04 19:12 被阅读0次

    Android11 最近任务Recents功能分析

    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()));
    
    

    相关文章

      网友评论

          本文标题:RecentsView 不显示已经结束的进程

          本文链接:https://www.haomeiwen.com/subject/txilljtx.html