为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

bsty 2015-12-28 15:26:47
在一个activity里有多个fragment,每个都有网络请求,在各个fragment之间切换时候短时间内不要重新发起请求,二是还原成上次的状态,即使fragment销毁了也能恢复,就像网易新闻那样。
查看完整描述

1 回答

?
星箜下

TA贡献34条经验 获得超10个赞

fragment之间切换,切换是不能请求,那下面的方法里就不能写网络请求的代码,写到onCreate()里。

切换到其他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

Fragment的销毁,onPause()后Fragment就有可能因为内存不足被回收。

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


查看完整回答
反对 回复 2016-01-22
  • 1 回答
  • 0 关注
  • 1214 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号