Home:ALL Converter>Fragment not retaining data

Fragment not retaining data

Ask Time:2018-06-08T22:00:59         Author:Demonic218

Json Formatter

I'm using some fragments in a tablayout, these fragments hold line charts, displaying data. However when I scroll a fragment or two away and come back the charts are empty, almost like the view was recreated.

Fragments are still very new to me so at this point i thought the fragment would pause and then resume, saving the view state.

I've found a method called setRetainInstance() which I've set to true, like such...

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRetainInstance(true);
    }

However the data is still getting lost, am I missing a step ?

Thanks for any tips/ advice.

Author:Demonic218,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762361/fragment-not-retaining-data
Rajen Raiyarela :

setRetainInstance is for retaining instance during the configuration change, It will not store your data. For data you need to implement saving data in onSaveInstanceState method and reloading data in onActivityCreated method.",
2018-06-08T14:05:56
yy