官网帮助文档链接:
http://developer.android.com/guide/components/fragments.html

主要看两张图,和跑代码

一,Fragment的生命周

二,与Activity生命周期的对比

场景演示 : 切换到该Fragment

11-29 14:26:35.095: D/AppListFragment(7649): onAttach
11-29 14:26:35.095: D/AppListFragment(7649): onCreate
11-29 14:26:35.095: D/AppListFragment(7649): onCreateView
11-29 14:26:35.100: D/AppListFragment(7649): onActivityCreated
11-29 14:26:35.120: D/AppListFragment(7649): onStart
11-29 14:26:35.120: D/AppListFragment(7649): onResume

屏幕灭掉:

11-29 14:27:35.185: D/AppListFragment(7649): onPause
11-29 14:27:35.205: D/AppListFragment(7649): onSaveInstanceState
11-29 14:27:35.205: D/AppListFragment(7649): onStop


屏幕解锁

11-29 14:33:13.240: D/AppListFragment(7649): onStart
11-29 14:33:13.275: D/AppListFragment(7649): onResume


切换到其他Fragment:
11-29 14:33:33.655: D/AppListFragment(7649): onPause
11-29 14:33:33.655: D/AppListFragment(7649): onStop
11-29 14:33:33.660: D/AppListFragment(7649): onDestroyView


切换回本身的Fragment:

11-29 14:33:55.820: D/AppListFragment(7649): onCreateView
11-29 14:33:55.825: D/AppListFragment(7649): onActivityCreated
11-29 14:33:55.825: D/AppListFragment(7649): onStart
11-29 14:33:55.825: D/AppListFragment(7649): onResume

回到桌面

11-29 14:34:26.590: D/AppListFragment(7649): onPause
11-29 14:34:26.880: D/AppListFragment(7649): onSaveInstanceState
11-29 14:34:26.880: D/AppListFragment(7649): onStop

回到应用

11-29 14:36:51.940: D/AppListFragment(7649): onStart
11-29 14:36:51.940: D/AppListFragment(7649): onResume


退出应用

11-29 14:37:03.020: D/AppListFragment(7649): onPause
11-29 14:37:03.155: D/AppListFragment(7649): onStop
11-29 14:37:03.155: D/AppListFragment(7649): onDestroyView
11-29 14:37:03.165: D/AppListFragment(7649): onDestroy
11-29 14:37:03.165: D/AppListFragment(7649): onDetach


比Activity多了一些生命周期,完整和Activity对接上,大家好好利用。

更多相关文章

  1. android P-sensor (Proximity Sensor)
  2. android游戏引擎libgdx学习笔记一
  3. Android(安卓)进入后台触发的事件,一般用于APP屏幕解锁
  4. android获取屏幕的尺寸,宽度和高度
  5. Android中横竖屏切换时Activity的生命周期
  6. Android(安卓)OpenGL ES 开发教程(10):绘制线段Line Segment
  7. Android之dialog实现底部出现对话框
  8. android 国际化 屏幕适配 样式和主题
  9. android图片资源的适配问题

随机推荐

  1. Android(安卓)常用mimetype类型
  2. Android自学笔记(番外篇):全面搭建Linux环境
  3. 【工具类】Android获取平板物理唯一标识
  4. Android(安卓)自定义Drawable 实现圆角矩
  5. android8.0 反射Application 启动过程
  6. Aosp build mini_emulator_x86_64-userde
  7. Android(安卓)-- 跳转应用市场评分
  8. 固定定位做的登录页面案例
  9. vw+rem移动端响应式布局
  10. 20个常用正则表达式