Save Action Bar Tab Fragment State

I am creating an application that is composed of a tabbed action bar and each tab is composed of a fragment. One of the fragments contains data that needs to be loaded. So I only want the data to be loaded the first time. When the user changes tabs and returns to the one containing this snippet, it doesn't wait for the data to be loaded again. I guess I need to use some sort of data persistence so that it can be used the next time the user comes back to that particular snippet. But I just don't know which method I should be using. If anyone knows or can suggest an example of persisting fragment state, please let me know. Thank u!


source to share

1 answer

Try the following:



This will mean that the fragment is not recreated every time it is added.



All Articles