Activity窗口的添加过程
- 1、查看Activity启动Stack trace
- 2、主要回调onResume之后执行makeVisible()
- * 简易时序图
1、查看Activity启动Stack trace
启动流程 AMS:startActivity桌面启动应用
05-25 15:15:30.356 1000 2176 3709 I wm_stack_created: 36
05-25 15:15:30.362 1000 2176 3709 I wm_create_task: [0,36]
05-25 15:15:30.362 1000 2176 3709 I wm_create_activity: [0,261377335,36,com.xhbruce.startactivitytest/.MainActivity,android.intent.action.MAIN,NULL,NULL,270532608]
05-25 15:15:30.364 1000 2176 3709 I wm_pause_activity: [0,182471102,com.miui.home/.launcher.Launcher,userLeaving=true]
05-25 15:15:30.367 1000 2176 2227 I am_uid_running: 10224
05-25 15:15:30.376 10083 2962 2962 I wm_on_top_resumed_lost_called: [182471102,com.miui.home.launcher.Launcher,topStateChangedWhenResumed]
05-25 15:15:30.384 10083 2962 2962 I wm_on_paused_called: [0,com.miui.home.launcher.Launcher,performPause,1]
05-25 15:15:30.388 1000 2176 3709 I wm_add_to_stopping: [0,182471102,com.miui.home/.launcher.Launcher,makeInvisible]
05-25 15:15:30.398 1000 2176 2237 I am_proc_start: [0,16819,10224,com.xhbruce.startactivitytest,pre-top-activity,{com.xhbruce.startactivitytest/com.xhbruce.startactivitytest.MainActivity}]
05-25 15:15:30.450 1000 2176 7561 I am_proc_bound: [0,16819,com.xhbruce.startactivitytest]
05-25 15:15:30.452 1000 2176 7561 I wm_restart_activity: [0,261377335,36,com.xhbruce.startactivitytest/.MainActivity]
05-25 15:15:30.453 1000 2176 7561 I wm_set_resumed_activity: [0,com.xhbruce.startactivitytest/.MainActivity,minimalResumeActivityLocked]
05-25 15:15:30.464 1000 2176 2227 I am_uid_active: 10224
05-25 15:15:31.208 10224 16819 16819 I wm_on_create_called: [0,com.xhbruce.startactivitytest.MainActivity,performCreate,168]
05-25 15:15:31.214 10224 16819 16819 I wm_on_start_called: [0,com.xhbruce.startactivitytest.MainActivity,handleStartActivity,3]
05-25 15:15:31.216 10224 16819 16819 I wm_on_resume_called: [0,com.xhbruce.startactivitytest.MainActivity,RESUME_ACTIVITY,1]
05-25 15:15:31.225 10224 16819 16819 I wm_on_top_resumed_gained_called: [261377335,com.xhbruce.startactivitytest.MainActivity,topStateChangedWhenResumed]
05-25 15:15:31.315 1000 2176 2235 I wm_activity_launch_time: [0,261377335,com.xhbruce.startactivitytest/.MainActivity,963]
05-25 15:15:31.355 1000 2176 3237 I wm_stop_activity: [0,182471102,com.miui.home/.launcher.Launcher]
05-25 15:15:31.357 10083 2962 2962 I wm_on_stop_called: [0,com.miui.home.launcher.Launcher,STOP_ACTIVITY_ITEM,2]
05-25 15:15:36.367 1000 2176 2235 I am_pss : [16704,10098,com.google.android.packageinstaller,6713344,5554176,440320,70320128,0,19,3]
05-25 15:15:57.007 1000 2176 2236 I am_uid_idle: 10219
05-25 15:15:30.351 1000 2176 3709 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.xhbruce.startactivitytest/.MainActivity bnds=[838,180][1006,348] (has extras)} from uid 10083
05-25 15:15:30.394 root 721 721 D Zygote : Forked child process 16819
05-25 15:15:31.207 10224 16819 16819 W System.err: java.lang.Exception: Stack trace
05-25 15:15:31.208 10224 16819 16819 W System.err: at java.lang.Thread.dumpStack(Thread.java:1529)
05-25 15:15:31.208 10224 16819 16819 W System.err: at com.xhbruce.startactivitytest.MainActivity.onCreate(MainActivity.java:46)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.Activity.performCreate(Activity.java:8143)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.Activity.performCreate(Activity.java:8114)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3513)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.os.Looper.loop(Looper.java:236)
05-25 15:15:31.208 10224 16819 16819 W System.err: at android.app.ActivityThread.main(ActivityThread.java:8060)
05-25 15:15:31.208 10224 16819 16819 W System.err: at java.lang.reflect.Method.invoke(Native Method)
05-25 15:15:31.208 10224 16819 16819 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
05-25 15:15:31.208 10224 16819 16819 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
05-25 15:15:31.213 10224 16819 16819 W System.err: java.lang.Exception: Stack trace
05-25 15:15:31.213 10224 16819 16819 W System.err: at java.lang.Thread.dumpStack(Thread.java:1529)
05-25 15:15:31.213 10224 16819 16819 W System.err: at com.xhbruce.startactivitytest.MainActivity.onStart(MainActivity.java:52)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1436)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.Activity.performStart(Activity.java:8174)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3566)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
05-25 15:15:31.213 10224 16819 16819 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
05-25 15:15:31.214 10224 16819 16819 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
05-25 15:15:31.214 10224 16819 16819 W System.err: at android.os.Looper.loop(Looper.java:236)
05-25 15:15:31.214 10224 16819 16819 W System.err: at android.app.ActivityThread.main(ActivityThread.java:8060)
05-25 15:15:31.214 10224 16819 16819 W System.err: at java.lang.reflect.Method.invoke(Native Method)
05-25 15:15:31.214 10224 16819 16819 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
05-25 15:15:31.214 10224 16819 16819 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
05-25 15:15:31.216 10224 16819 16819 W System.err: java.lang.Exception: Stack trace
05-25 15:15:31.216 10224 16819 16819 W System.err: at java.lang.Thread.dumpStack(Thread.java:1529)
05-25 15:15:31.216 10224 16819 16819 W System.err: at com.xhbruce.startactivitytest.MainActivity.onResume(MainActivity.java:58)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1457)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.Activity.performResume(Activity.java:8298)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4554)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4596)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.os.Looper.loop(Looper.java:236)
05-25 15:15:31.216 10224 16819 16819 W System.err: at android.app.ActivityThread.main(ActivityThread.java:8060)
05-25 15:15:31.216 10224 16819 16819 W System.err: at java.lang.reflect.Method.invoke(Native Method)
05-25 15:15:31.216 10224 16819 16819 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
05-25 15:15:31.216 10224 16819 16819 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
2、主要回调onResume之后执行makeVisible()
启动流程 AMS:startActivity桌面启动应用、四大组件:Activity生命周期-Android12
主要回调onResume之后执行makeVisible(),最终调用到
WindowManagerService.java#addWindow
,可参考Activity的预览窗口StartingWindow添加流程WindowManagerGlobal.java#addView -> ViewRootImpl.java#setView -> Session extends IWindowSession.Stub#addToDisplayAsUser -> WindowManagerService.java#addWindow