赵雅智_Fragment生命周期
官網幫助文檔鏈接:
?http://developer.android.com/guide/components/fragments.html
主要看兩張圖。和跑代碼
一,Fragment的生命周?
? ? ? ? ??
二,與Activity生命周期的對照
? ? ?
(1)、onAttach()//當一個Fragment對象關聯到一個Activity時調用。
(2)、onCreate()//初始創建Fragment對象時調用。
(3)、onCreateView()//創建與Fragment對象關聯的View視圖時調用。
(4)、onActivityCreated()//當Activity對象完畢自己的onCreate方法時調用。
(5)、onStart()//Fragment對象在ui可見時調用。
(6)、onResume()//Fragment對象的ui能夠與用戶交互時調用。
(7)、onPause()//Fragment對象可見,但不可交互。
有Activity對象轉為onPause狀態時調用。
(8)、onStop()//有空間全然遮擋;或者宿主Activity對象轉為onStop狀態時調用。
(9)、onDestroyView()//Fragment對象清理view資源時調用,也就是移除fragment中的視圖。
(10)、onDestroy()//Fragment對象完畢對象清理View資源時調用。
(11)、onDetach()//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
總結
以上是生活随笔為你收集整理的赵雅智_Fragment生命周期的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS 手机助手及越狱助手推荐
- 下一篇: 【JavaScript】出现即使设置了I