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

Android中Fragment與Activity的生命周期對(duì)比

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

Fragment必須是依存于Activity而存在的,因此Activity的生命周期會(huì)直接影響到Fragment的生命周期。官網(wǎng)這張圖很好的說(shuō)明了倆者的關(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相對(duì)應(yīng),當(dāng)改Fragment被移除時(shí)調(diào)用

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

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

場(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

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

相關(guān)文章

最新評(píng)論

江门市| 郯城县| 临颍县| 武陟县| 两当县| 西宁市| 阿拉善右旗| 航空| 扶沟县| 堆龙德庆县| 清河县| 安达市| 罗平县| 古浪县| 织金县| 阆中市| 湘潭县| 贵溪市| 武城县| 灵石县| 澳门| 三原县| 桐乡市| 新疆| 兴业县| 嘉荫县| 拜泉县| 雷山县| 贵港市| 巴马| 醴陵市| 隆德县| 荆州市| 嘉兴市| 荃湾区| 阜南县| 南丹县| 广宗县| 泗阳县| 广丰县| 五寨县|