In my application I have activity A.Upon clicking a button on this Activity, app launches Activity B.Inside Activity B's onCreate() I add a fragment.Everytime a fragment is created it loads a list from External Server using AsyncTask.
How can I persist this list on configuration changes?I have looked for many solutions but many suggest using 'android:configchanges' in manifest which I am totally against using.Many suggest and I have read about it also - to use setRetainInstance(true) in Fragment that would retain the fragment.
I have tried to implement it but I failed.Many tutorials after orientation changes check for the Fragment using findFragmentByTag but in my case it always returns null.Can anybody please post proper tutorial or proper answer on how to use RetainFragments?
Also I am calling AsyncTask to load list in onActivityCreated method in Fragment.According to android documentation when using setRetainInstance(true),onCreate(Bundle) will not be called since the fragment is not being re-created. onAttach(Activity) and onActivityCreated(Bundle) will still be called.
So should I call AsyncTask in onCreate Method?