saving fragment state actionbar tab

社会主义新天地 提交于 2019-12-07 16:21:35

问题


I am building an app that consists of actionbar with tabs, and each tab consists of a fragment. One of the fragments has data that need to be loaded. So I want the data to be loaded only the first time. When the user changes the tabs and goes back to the one containing that fragment, doesn't wait for the data to be loaded again. I assume I have to use some kind of saving the data so that it can be used the next time the user goes back to that particular fragment. But I just do not know what method I should use. If someone knows or can suggest an example of saving fragment state, please let me know. Thank u!


回答1:


Try this:

myFragment.setRetainInstance(true);

It'll mean the fragment isn't recreated every time it's added.



来源:https://stackoverflow.com/questions/9804730/saving-fragment-state-actionbar-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!