onCreate
1. ApplicationThread#schedueLaunchActivity
2. ActivityThread#handleLaunchActivity
3. ActivityThread#performLaunchActivity
4. Activity#attach
调用Activity.setContentView
1. PhoneWindow#installDecor(初始化DecorView及ContentParent)
2. mLayoutInflater.inflate(layoutResID, mContentParent);
#inflate此处
LayoutInflator#rInflate 最终finishInflate=true:触发parent.onFinishInflate();
LayoutInflator#createView#constructor.newInstance(args);最终调用 XXX(Context context, AttrsSet args);
# 至此,View对象们已经存在mContentParent的子对象中.
onResume
- ActivityThread#performResumeActivity
- Activity#performResume
2.1 performResume#performRestart
2.2 触发performStart,调试模式弹窗,-> enterReady
2.2.1 activity.getWindow().getDecorView().setVisibility(View.VISIBLE);
2.2.2 triggerViewsReady#decor.invalidate();
2.2.3 View#invalidateInternal内
// Propagate the damage rectangle to the parent view.
final AttachInfo ai = mAttachInfo;
final ViewParent p = mParent;
if (p != null && ai != null && l < r && t < b) {
final Rect damage = ai.mTmpInvalRect;
damage.set(l, t, r, b);
# All or part of a child is dirty and needs to be redrawn.
p.invalidateChild(this, damage);
}
ViewRootImpl#scheduleTraversals#最终会重绘界面 onMeasure/onLayout/onDraw
2.3 onResume
DecorView extends FrameLayout
- 根布局
- mContentParent
ViewRootImpl
- 实现View和WindowManager之间的协议。具体详看WindowManagerGlobal
WindowManagerGlobal
- 维护View ViewRootImpl LayoutParams的顺序存储。
updateViewLayout和removeView都是在ViewRootImpl的基础上进行操作的
view.invalidate最终也是调用到ViewRootImpl#scheduleTraversals,其performMeasure/Layout/Draw
ViewRootImpl的内部缓存View对象
WindowManager的实现类WindowManagerImpl的内部调用WindowManagerGlobal的具体实现。