3个阶段:
第一阶段 :
主要是在本地执行:(主要在与Activity-->Instrumentation之间)
第二阶段 :
主要进入 AcitivityManagerService,最终会进入ActivityStack,主要是对Activity 的历史栈的一个整理管理,对Activity启动是否具备权限检测,包装Intent,Acitivity属性配置,过渡动画,启动模式设置.
startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()),
token, target != null ? target.mEmbeddedID : null,
requestCode, 0, null, options)
==>mStackSupervisor.startActivityMayWait
==>startActivityLocked
==>startActivityUncheckedLocked
==>mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, intent, r.getUriPermissionsLocked(), r.userId);
==>targetStack.startActivityLocked(r, newTask, doResume, keepCurTransition, options);
==>resumeTopActivityInnerLocked
==>mStackSupervisor.startSpecificActivityLocked
==>realStartActivityLocked
第三阶段:
通过ActivityThread进行对Activity的初始化,加载包,从而触发Window创建
ActivityThread==>scheduleLaunchActivity
sendMessage(H.LAUNCH_ACTIVITY, r);
==>getPackageInfoNoCheck(r.activityInfo.applicationInfo, r.compatInfo)
==>handleLaunchActivity(r, null);
==>performLaunchActivity(r, customIntent);
getPackageInfo(aInfo.applicationInfo, r.compatInfo,
Context.CONTEXT_INCLUDE_CODE);
==> r.intent.getComponent();
==> r.packageInfo.getClassLoader()
//创建Activity生命周期,正式启动
==> r.packageInfo.makeApplication(false, mInstrumentation);
==> Context appContext = createBaseContextForActivity(r, activity);
==> activity.attach(appContext, this, getInstrumentation(), r.token,
r.ident, app, r.intent, r.activityInfo, title, r.parent,
r.embeddedID, r.lastNonConfigurationInstances, config,
r.referrer, r.voiceInteractor);
==> mInstrumentation.callActivityOnCreate(activity, r.state);