activity启动流程速记笔记
Activity.startActivity(Intent intent)----Activity.startActivityForResult(Intent intent)----Instrumentation.execStartActivity()----ActivityManagerNative.getDefault().startActivity
----ActivityManagerService----Binder----IActivityManager----ActivityManagerProxy----ActivityManagerService.startActivity
----ActivityManagerService.
startActivityAsUser设置了userId-----ActivityStackSuperviso.startActivityMayWait主要进行了Intent的检查----ActivityStackSuperviso.startActivityLocked生成ActivityRecord-----ActivityStackSuperviso.startActivityUncheckedLocked首先判断了启动模式------上面的步骤完成了Activity的目标栈的判断(targetStack)------ActivityStack.startActivityLocked将Activity添加到了栈顶,初始化了WindowManager--------StackSupervisor.resumeTopActivitiesLocked判断目标任务栈是否在前------ActivityStack.resumeTopActivityLocked确保当前栈顶的Activity是否resumed-------ActivityStack.resumeTopActivityInnerLocked 1,首先让现在正在运行的Activity调用startPausingLocked进入pause状态 2.如果要启动的Activity不为空且所在的进程存在的话,所在的进程执行scheduleResumeActivity启动Activity 3.如果Activity为空,所在的进程不存在,执行ActivityStackSupervisor.startSpecificActivityLocked
ActivityStack.startPausingLocked-------ApplicationThread.schedulePauseActivity主要handler发送消息-----ApplicationThread.handlePauseActivity----ApplicationThread.performPauseActivity----- callCallActivityOnSaveInstanceState(r)
----Instrumentation.callActivityOnPause---Activity.performPause---Activity.onPause()
ApplicationThread.handleReusmeActivity----ApplicationThread.performReusmeActivity-----
Instrumentation.callActivityOnReusme---Activity.performReusme---Activity.onReusme()
ActivityStackSupervisor.startSpecificActivityLocked------ActivityManagerService.startProcessLocked-----Process.start方法,并且传入类名android.app.ActivityThread-------startViaZygote-----zygoteSendArgsAndGetResult最后通过Zygote孵化出了我们刚才传入的ActivityThread,也就是我们很熟悉的应用入口进程,来到它的main方法----ActivityThread.main()------ Looper.prepareMainLooper()Looper.loop();
----ActivityThread thread = new ActivityThread(); thread.attach(false)---------ActivityManagerService.attachApplication----------ActivityManagerService.attachApplicationLocked-------ActivityStackSupervisor.realStartActivityLocked-------ApplicationThread.scheduleLaunchActivity-----ActivityThread.handleLaunchActivity----ActivityThread.performLaunchActivity----packageInfo.getClassLoader()
mInstrumentation.newActivity----- activity.attach(
---- mInstrumentation.callActivityOnCreate activity.performStart();
mInstrumentation.callActivityOnRestoreInstanceState(
----- prePerformCreate(activity); activity.performCreate(icicle, persistentState); postPerformCreate(activity);
---activity.performCreate()----activity.Create()
Looper.loop();
----ActivityThread thread = new ActivityThread(); thread.attach(false)---------ActivityManagerService.attachApplication----------ActivityManagerService.attachApplicationLocked-------ActivityStackSupervisor.realStartActivityLocked-------ApplicationThread.scheduleLaunchActivity-----ActivityThread.handleLaunchActivity----ActivityThread.performLaunchActivity----packageInfo.getClassLoader()
mInstrumentation.newActivity----- activity.attach(
---- mInstrumentation.callActivityOnCreate activity.performStart();
mInstrumentation.callActivityOnRestoreInstanceState(
----- prePerformCreate(activity); activity.performCreate(icicle, persistentState); postPerformCreate(activity);
---activity.performCreate()----activity.Create()
作者: 一点点征服
出处:http://www.cnblogs.com/ldq2016/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利