Android Activity启动流程 发表于 2020-11-29 更新于 2023-10-18 分类于 Android 本文介绍Android Activity的启动流程 startActivity流程ActivityActivityInstrumentationInstrumentationIActivityManagerIActivityManagerAMSAMSActivityStarterActivityStarterActivityRecordActivityStackSupervisorActivityStackSupervisorActivityStackActivityStackApplicationThreadApplicationThreadActivityThreadActivityThreadstartActivitystartActivityForResultexecStartActivitystartActivitystartActivitystartActivityAsUserstartActivityMayWaitstartActivityLockedstartActivityActivityRecordstartActivitystartActivityUncheckedresumeFocusedStackTopActivityLockedresumeTopActivityUncheckedLockedresumeTopActivityInnerLockedstartSpecificActivityLocked会判断是否启动新的进程realStartActivityLockedscheduleLaunchActivitysendMessage(H.LAUNCH_ACTIVITY, r)handleMessagestartProcessLocked需要启动进程 Activity启动流程ActivityThreadActivityThreadInstrumentationInstrumentationActivityPhoneWindowDecorViewWindowManagerImplWindowManagerImplWindowManagerGlobalWindowManagerGlobalViewRootImplhandleMessage.LAUNCH_ACTIVITYhandleLaunchActivityinitializeServiceManager.getService("window"))performLaunchActivitynewActivityClassLoader.loadClassnewInstanceActivityattachmWindowPhoneWindowsetWindowManagercallActivityOnCreateperformCreateonCreatesetContentViewDecorViewmContentParent.addViewperformStartcallActivityOnStartonStarthandleResumeActivityperformResumeActivityperformResumecallActivityOnResumeonResumeaddView(decorView)addViewViewRootImplmViews.add(view)mRoots.add(root)mParams.add(wparams)setView WindowManagerGlobalArrayList<View> mViews;ArrayList<ViewRootImpl> mRootsViewDecorViewViewRootImpl1n1n