So..
What I have is as follows, a complicated fragment based viewpager utilizing tabhosts etc with my activity. This is the basic setup.
Once this has been created, I use an AsyncTask to get some data from my database. When the ASyncTask is complete i find the respective fragments of the viewpager using the fragmentmanager and call functions within each fragment that set the data. For example, in fragment A the data is set as a list within a list adapter, and in fragment B the data is plotted on a map.
I have set it up this way as all the fragments use the same data, and I only want to have to call one ASyncTask. It works perfectly.
My problem is when a user rotates the screen whilst it is loading. So calling an ASyncTask from a fragment you can use setRetainInstance, and previously within an activity you could use onRetainNoneConfigurationInstance.. but that is now deprecated.
I have spent ages searching and no-one seems to have an answer for this specific situation..
Can anyone advise?
You can use an invisible
Fragmentto retain your state. It’s essentially the same asonRetainNoneConfigurationInstancebut not deprecated.see http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#config-changes
There is a bug in the example and you have to add the RetainFragment to the
FragmentManageror it’s not going to be restored.