android28 startActivity启动流程分析(三)--ActivityStarter:startActivity()

这一篇分析ActivityStarter:startActivity(),这个方法还是挺长的,分段来分析,当然了,只能分析我看得懂的→_→

这个方法主要是对启动Activity的异常排查,并且创建了跳转目标Activity的ActivtyRecord对象

<第一段  :获取callerApp-->当前进程对应的ProcessRecord对象 >

 int err = ActivityManager.START_SUCCESS;

//获取当前进程的ProcessRecord
 ProcessRecord callerApp = null;
        if (caller != null) {
            callerApp = mService.getRecordForAppLocked(caller);
            if (callerApp != null) {
                callingPid = callerApp.pid;
                callingUid = callerApp.info.uid;
            } else {
                Slog.w(TAG, "Unable to find app for caller " + caller
                        + " (pid=" + callingPid + ") when starting: "
                        + intent.toString());
                err = ActivityManager.START_PERMISSION_DENIED;
            }
        }

<第二段  :1、获取sourceRecord-->起始Acitivity在Activity栈中对应的ActivityRecord对象

                    2、标记startActivityForResult()启动方式

                          如果requestCode>0并且起始Activity没有finishi掉,那么resultRecord=sourceRecord,否则为null>

ActivityRecord sourceRecord = null;
ActivityRecord resultRecord = null;
 if (resultTo != null) {
    //获取起始Activity在栈中对应的ActivityRecord对象
     sourceRecord = mSupervisor.isInAnyStackLocked(resultTo);
     if (DEBUG_RESULTS) Slog.v(TAG_RESULTS,
            "Will send result to " + resultTo + " " + sourceRecord);
     if (sourceRecord != null) {
          //如果用户以startActivityForResult方式启动,并且起始Activity没有finish,
         那么将resultRecord也记为sourceRecord
          if (requestCode >= 0 && !sourceRecord.finishing) {
               resultRecord = sourceRecord;
          }      
     }
}              

<第三段 启动参数异常排查>

if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) {
            // We couldn't find a class that can handle the given Intent.
            // That's the end of that!
            err = ActivityManager.START_INTENT_NOT_RESOLVED;
        }
......//N个省略

<第四段 创建r对象--跳转目标Activity对应的ActivityRecord对象>

 ActivityRecord r = new ActivityRecord(mService, callerApp, callingPid, callingUid,
                callingPackage, intent, resolvedType, aInfo, 
                mService.getGlobalConfiguration(),
                resultRecord, resultWho, requestCode, componentSpecified, 
               voiceSession != null, mSupervisor, checkedOptions, sourceRecord);

//此处的outActivity是ActivityStarter成员变量mLastStartActivityRecord,声明时即创建了长度是1的数组,所以此处不为null
 if (outActivity != null) {
            outActivity[0] = r;
        }
......
 return startActivity(r, sourceRecord, voiceSession, voiceInteractor, startFlags,
                true /* doResume */, checkedOptions, inTask, outActivity);

到这里再列一下传入的参数

参数
r 目标Activity对应的ActivityRecord对象
sourceRecord 起始Activity对应的ActivityRecord对象
voiceSession 不认识,不懂、不会
voiceInteractor 不认识,不懂、不会
startFlags 0
doResume true
checkedOptions 不认识,不懂、不会
inTask null
outActivity 长度是1的ActivityRecord数组,元素为r

 

你可能感兴趣的:(android28 startActivity启动流程分析(三)--ActivityStarter:startActivity())