ActivityTaskSupervisor:
ActivityTaskSupervisor.activityIdleInternal>processStoppingAndFinishingActivities>
ActivityRecord.stopPossible{
mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
StopActivityItem.obtain(configChangeFlags));
}
重点关注ActivityThread.handleXXX方法:
handleReLaunchActivity>
performDestroyActivity>
r.activity.retainNonConfigurationInstances();//保存 viewmodel等信息传递到新Activity
handleLaunchActivity>
unscheduleGcIdler();//取消在后台接受GC的消息
WindowManagerGlobal.initialize();//WMS 初始化
performLaunchActivity>
newActivity//反射创建 activity
makeApplicationif: (mApplication != null) return mApplication;
activity.attach>
attachBaseContext
new PhoneWindow()
if (theme != 0) {
activity. setTheme(theme) ;
}
if (r.isPersistable()) {// 区分持久化,调用onCreat
mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);
} else {
mInstrumentation.callActivityOnCreate(activity, r.state);
}
handleResumeActivity>
unscheduleGcIdler();
performResumeActivity>
activity.performResume>
dispatchActivityPreResumed//全局callback 回调
performStart/performRestart
mInstrumentation.callActivity OnResume (this);
mFragments.dispatchResume();
dispatchActivityPostResumed();全局callback 回调
if (r.window == null && !a.mFinished && willBeVisible) >//不考虑 onCreate中setContrentView触发了Window绑定
r.window = r.activity.getWindow();//PhoneWindow
View decor = r.window.getDecorView();
ViewManager wm = a.getWindowManager();//WindowManagerGlobal
wm.addView(decor, l)>//完成 viewRootImpl 与DecorView关联
Root = new ViewRootImpl()
root.setView(view:DecorView)>
requestLayout();//触发第一个粗略布局
Looper.myQueue().addIdleHandler(new Idler())>;//插入一条Idler消息
ac.activityIdle(a.token, a.createdConfig, stopProfiling)>//给所有没有
ActivityClientController.activityIdle>//ActivityClientController是一个 IBinder
activityIdleInternal>
mHandler.removeMessages( IDLE_TIMEOUT_MSG , r);
mHandler.removeMessages( LAUNCH_TIMEOUT_MSG );
processStoppingAndFinishingActivities>
if (r.isInHistory()) {
if ( r.finishing ) {
// TODO(b/137329632): Wait for idle of the right activity, not just any.
r.destroyIfPossible(reason);
} else {
r.stopIfPossible();>
}
}