Android--startActivityLocked

来源:互联网 发布:淘宝怎么防举报防排查 编辑:程序博客网 时间:2024/06/07 02:35

startActivityLocked(ActivityRecord r, boolean newTask,boolean doResume, boolean keepCurTransition, Bundle options)

传入的参数为:

ActivityRecord r:要启动的Activity的ActiviryRecord

boolean newTask:是否在一个新的Task中启动

boolean doResume:是否立刻启动

boolean keepCurTransition

Bundle options:一般为NULL,否则就是调用者传进来的

if (!newTask) {            // If starting in an existing task, find where that is...            boolean startIt = true;            for (int i = NH-1; i >= 0; i--) {                ActivityRecord p = mHistory.get(i);                if (p.finishing) {                    continue;                }                if (p.task == r.task) {                    // Here it is!  Now, if this is not yet visible to the                    // user, then just add it without starting; it will                    // get started when the user navigates back to it.                    addPos = i+1;                    if (!startIt) {                        if (DEBUG_ADD_REMOVE) {                            RuntimeException here = new RuntimeException("here");                            here.fillInStackTrace();                            Slog.i(TAG, "Adding activity " + r + " to stack at " + addPos,                                    here);                        }                        mHistory.add(addPos, r);                        r.putInHistory();                        mService.mWindowManager.addAppToken(addPos, r.appToken, r.task.taskId,                                r.info.screenOrientation, r.fullscreen);                        if (VALIDATE_TOKENS) {                            validateAppTokensLocked();                        }                        ActivityOptions.abort(options);                        return;                    }                    break;                }                if (p.fullscreen) {                    startIt = false;                }            }        }

首先判断是否要新建一个Task,通过newTask标志位来判断,如果为false ,代表不需要创建新的Task,然后遍历mHistory:

1.如果ActivityRecord.finishing说明该Activity正在finish中,那么跳过

2.判断ActivityRecord的TaskId与要启动的Activity的Task是否相同,



0 0