Fragment生命周期_Android Fragment详解
2014-09-05 13:57:17  By: shinyuu

Fragment 生命周期其实跟 Activity 的生命周期区别不大、目前关于这块的文档也不少

我之所以写下来的目的是为了自己以后方便、另外还可以帮助一部分朋友了解 Fragment 生命周期

下面有一张图、可以形象的解说 Fragment 生命周期

场景演示 : 切换到该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对接上,大家好好利用

若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力

想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)

或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)

如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教

为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)

感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛


快速评论


技术评论

  • 该技术还没有评论、赶快抢沙发吧...
DD记账
top
+