Fragment 是 Activity 的一个组件片段,也就是说他的生命周期
是依赖于 Activity 的
但是它比 Activity 多了几个生命步骤,
- 首先是Activity#onCreate 中Fragment会执行onAttach()、onCreate()、onCreateView()、onActivityCreated()
- 接着Activity#onStart()中Fragment也会执行onStart()
- 然后是Activity#onResume()中Fragment也会执行onResume()
- 接着是Activity#onPause()中Fragment也会执行onPause()(先于Activity执行)
- 然后是Activity#onStop()中Fragment也会执行onStop()(先于Activity执行)
- 接着是Activity#onDestroy()中Fragment会执行onDestroyView()、onDestroy()、onDetach()(先于Activity执行)