1. Fragment的生命周期
见下图
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuEWZiJjY1AjZiBjZyYDN2YzMzkDOxQzM1cjMzcDOzATNfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
2. 与Activity生命周期的对比
3. 代码场景演示实例
切换到该Fragment:
AppListFragment(7649): onAttach
AppListFragment(7649): onCreate
AppListFragment(7649): onCreateView
AppListFragment(7649): onActivityCreated
AppListFragment(7649): onStart
AppListFragment(7649): onResume
屏幕灭掉:
AppListFragment(7649): onPause
AppListFragment(7649): onSaveInstanceState
AppListFragment(7649): onStop
屏幕解锁
切换到其他Fragment:
AppListFragment(7649): onDestroyView
切换回本身的Fragment:
回到桌面
回到应用
D/AppListFragment(7649): onStart
退出应用
AppListFragment(7649): onDestroy
AppListFragment(7649): onDetach