赵雅智_Fragment生命周期
官網(wǎng)幫助文檔鏈接:
?http://developer.android.com/guide/components/fragments.html
主要看兩張圖。和跑代碼
一,Fragment的生命周?
? ? ? ? ??
二,與Activity生命周期的對(duì)照
? ? ?
(1)、onAttach()//當(dāng)一個(gè)Fragment對(duì)象關(guān)聯(lián)到一個(gè)Activity時(shí)調(diào)用。
(2)、onCreate()//初始創(chuàng)建Fragment對(duì)象時(shí)調(diào)用。
(3)、onCreateView()//創(chuàng)建與Fragment對(duì)象關(guān)聯(lián)的View視圖時(shí)調(diào)用。
(4)、onActivityCreated()//當(dāng)Activity對(duì)象完畢自己的onCreate方法時(shí)調(diào)用。
(5)、onStart()//Fragment對(duì)象在ui可見時(shí)調(diào)用。
(6)、onResume()//Fragment對(duì)象的ui能夠與用戶交互時(shí)調(diào)用。
(7)、onPause()//Fragment對(duì)象可見,但不可交互。
有Activity對(duì)象轉(zhuǎn)為onPause狀態(tài)時(shí)調(diào)用。
(8)、onStop()//有空間全然遮擋;或者宿主Activity對(duì)象轉(zhuǎn)為onStop狀態(tài)時(shí)調(diào)用。
(9)、onDestroyView()//Fragment對(duì)象清理view資源時(shí)調(diào)用,也就是移除fragment中的視圖。
(10)、onDestroy()//Fragment對(duì)象完畢對(duì)象清理View資源時(shí)調(diào)用。
(11)、onDetach()//Fragment對(duì)象沒有與Activity對(duì)象關(guān)聯(lián)時(shí)調(diào)用。
場(chǎng)景演示 : 切換到該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
回到應(yīng)用
11-29 14:36:51.940: D/AppListFragment(7649): onStart
11-29 14:36:51.940: D/AppListFragment(7649): onResume
退出應(yīng)用
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
總結(jié)
以上是生活随笔為你收集整理的赵雅智_Fragment生命周期的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS 手机助手及越狱助手推荐
- 下一篇: Bootstrap学习3