Activity启动过程
Activity
1.startActivity
2.startActivityForResult
Instrumentation
3.execStartActivity
ActivityManagerService
4.startActivity
5.startActivityAsUser
ActivityStarter
6.startActivityMayWait
解析出Intent相匹配的Activityinfo
得到启动Activity的Task
7.startActivityLocked
禁止App切换恢复
校验参数
8.startActivityUnchecked
ActivityStackSupervisor
9.resumeFocusedStackTopActivityLocked
ActivityStack
10.resumeTopActivityUncheckedLocked
11.resumeTopActivityInnerLocked
判断是否又resume的Activity有则暂停
唤醒目标ActivityActivity或重启Acitivity
ActivityStackSupervisor
12.startSpecificActivityLocked
没有启动app的,通过zygote创建应用进程startProcessLocked
启动了了进入14步启动realStartActivityLocked
ActivityManagerService
13.startProcessLocked
ActivityStackSupervisor
14.realStartActivityLocked
通过发送事务执行事务 最后执行LaunchActivityItem 和ResumeActivityItem 的execute
最终调用activityThread.handleLaunchActivity, activityThread.handleResumeActivity
handleLaunchActivity 会调用performLaunchActivity
mInstrumentation.newActivity 创建acitivty
activity.attach 创建phonewindow
mInstrumentation.callActivityOnCreate
调用created 调用onCreated 中window.setContentView生成dectoView
handleResumeActivity
WindowManagerGlobal把dectoView添加到window addView 会生ViewRootImpl
scheduleTraversals performTraversals performMeasure performLayout performDraw view绘画工作机制
1 | // Create activity launch transaction. |
ActivityThread.this.scheduleTransaction
ActivityThread 的父类
1 | public abstract class ClientTransactionHandler { |
ActivityThread H 中
1 | case EXECUTE_TRANSACTION: |
LaunchActivityItem 中
1 | @Override |