Reputation: 4259
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!
Upvotes: 3
Views: 3323
Reputation: 28519
Try this:
myFragment.setRetainInstance(true);
It'll mean the fragment isn't recreated every time it's added.
Upvotes: 3