最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中Fragment與Activity的生命周期對比

 更新時(shí)間:2016年02月25日 11:54:30   作者:高杰才_(tái)Android  
這篇文章主要介紹了Android中Fragment與Activity的生命周期對比,Fragment是在Activity的基礎(chǔ)之上進(jìn)行設(shè)計(jì)的,比Activity多出幾個(gè)控制生命周期的回調(diào)函數(shù),需要的朋友可以參考下

Fragment必須是依存于Activity而存在的,因此Activity的生命周期會(huì)直接影響到Fragment的生命周期。官網(wǎng)這張圖很好的說明了倆者的關(guān)系:

2016225115117535.jpg (373×684)

可以看到Fragment比Activity多了幾個(gè)額外的生命周期回調(diào)函數(shù):

onAttach(Activity);  //當(dāng)Activity與Fragment發(fā)生關(guān)聯(lián)時(shí)調(diào)用

onCreateView(LayoutInflater,ViewGroup,Bundle);  //創(chuàng)建該Fragment的視圖

onActivityCreate(bundle);  //當(dāng)Activity的onCreate();方法返回時(shí)調(diào)用

onDestoryView();  //與onCreateView相對應(yīng),當(dāng)改Fragment被移除時(shí)調(diào)用

onDetach();  //與onAttach()相對應(yīng),當(dāng)Fragment與Activity的關(guān)聯(lián)被取消時(shí)調(diào)用

注意:除了onCreateView,其他的所有方法如果你重寫了,必須調(diào)用父類對于該方法的實(shí)現(xiàn)。

場景演示 :

切換到該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

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

相關(guān)文章

最新評論

雷波县| 石阡县| 南通市| 循化| 松潘县| 临沂市| 泰兴市| 龙州县| 澎湖县| 克东县| 广东省| 曲麻莱县| 余姚市| 左云县| 常山县| 黔西| 卢湾区| 辉南县| 哈尔滨市| 鹿邑县| 济源市| 南宁市| 唐河县| 汶川县| 峡江县| 连平县| 潮州市| 罗源县| 平陆县| 禹城市| 松原市| 千阳县| 木兰县| 江都市| 大埔县| 文化| 黔江区| 陈巴尔虎旗| 资阳市| 铁力市| 栖霞市|