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.callActivityOnPauseActivity.performPauseActivity.onPause()

   

ApplicationThread.handleReusmeActivity—-ApplicationThread.performReusmeActivity—– Instrumentation.callActivityOnReusmeActivity.performReusmeActivity.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()

    原文作者:一点点征服
    原文地址: http://www.cnblogs.com/ldq2016/p/10243592.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞