ragment销毁还能恢复数据和状态怎么实现?


在一个activity里有多个fragment,每个都有网络请求,在各个fragment之间切换时候短时间内不要重新发起请求,二是还原成上次的状态,即使fragment销毁了也能恢复,就像网易新闻那样。

bsty
浏览 1215回答 1
1回答

星箜下

fragment之间切换,切换是不能请求,那下面的方法里就不能写网络请求的代码,写到onCreate()里。切换到其他Fragment:11-29 14:33:33.655: D/AppListFragment(7649): onPause11-29 14:33:33.655: D/AppListFragment(7649): onStop11-29 14:33:33.660: D/AppListFragment(7649): onDestroyView切换回本身的Fragment:11-29 14:33:55.820: D/AppListFragment(7649): onCreateView11-29 14:33:55.825: D/AppListFragment(7649): onActivityCreated11-29 14:33:55.825: D/AppListFragment(7649): onStart11-29 14:33:55.825: D/AppListFragment(7649): onResumeFragment的销毁,onPause()后Fragment就有可能因为内存不足被回收。11-29 14:37:03.020: D/AppListFragment(7649): onPause11-29 14:37:03.155: D/AppListFragment(7649): onStop11-29 14:37:03.155: D/AppListFragment(7649): onDestroyView11-29 14:37:03.165: D/AppListFragment(7649): onDestroy11-29 14:37:03.165: D/AppListFragment(7649): onDetach
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android