// Activity A 启动:
A:onCreate
V:onFinishInflate
A:onStart
A:onResume
V:onAttachedToWindow
V:onMeasure
V:onSizeChanged
V:onLayout
V:onDraw
A:onWindowFocusChanged
V:onWindowFocusChanged
// Activity A 跳转 Activity B
A:onPause
A: onWindowFocusChanged
V:onWindowFocusChanged
A: onStop
V:onSaveInstanceState
// Activity B 返回 Activity A
A:onReStart
A: onStart
A:onResume
V : onDraw
V:onWindowFocusChanged
// Activity A 横竖屏切换
A: onConfigurationChanged
V:onConfigurationChanged
V: onMeasure
V:onMeasure
V: onLayout
V: onDraw
// Activity A 结束
A:onPause
A: onWindowFocusChanged
V:onWindowFocusChanged
A:onStop
A:onDestroy
V:onDetachedFromWindow
注意:
Activity执行onCreate之后初始化View,View执行onFinishInflate
在Activity A 执行onResume之后,View进行绘制并处于在进程的前台模式获取焦点onAttachedToWindow->onMeasure->onSizeChanged->onLayout->onDraw->onWindowFocusChanged
当Activity A 跳转 Activity B 时, view 在onStop之后保存状态(Activity跳转的过程是在同一个线程内同步执行的,所以在onStop之后对View的状态进行保存避免因为保存状态时间过长导致切换到B时的卡顿),view由进程的前台模式转变为可见模式,丢失焦点执行onWindowFocusChanged
Activity B 返回A时。View会重新走onDraw、onWindowFocusChanged 绘制并由进程的背景模式转为可见模式再转为前台模式重新获取焦点,再次执行onWindowFocusChanged
Activity A 结束时,进程由前台模式变为背景模式,view丢失焦点,在Activity执行onDestroy()之后,view执行onDetachedFromWindow,离开窗口