Hello,

I am currently working on a tab-based app. I am using Fragments for the tabs, and in some of these fragments I am using a Loader to perform background loading of data from the internet. This seems to currently be the most recommended way to go. In order to prevent the data from getting re-loaded from the internet each time the device rotates, I have setRetainInstance(true) on the fragments which do this. This works fine, and the loader properly gets retained, as long as you are viewing the tab during the rotation. It also seems to work if you rotate at least once on the tab before switching to another tab and rotating. However, I am experiencing the following behavior:
Visit the tab which has the loader.  Allow it to load.
Switch away from that tab.
Rotate the device.  Rotate back or not, doesn't matter.
* at this point, my onLoaderReset method gets called.
Switch back to the tab with the loader.
* the fragment's onCreate is invoked, which calls getLoaderManager().initLoader(...) No further loader callbacks are made, and my app just sits with a loading spinner forever. Looking at member variables in the debugger in onCreate, it seems the loader manager is marked as destroyed at this point (variable mDestroyed is true).

This can be reproduced in the compatibility library samples, as well as the 3.2 api demo sample, by doing the following: Edit com/example/android/apis/app/LoaderCustom.java (or com/example/android/support4/app/LoaderCustomSupport.java for the Support4Demos), adding the following method to the AppListFragment class:
@Override public void onStart() {
   super.onStart();
   setRetainInstance(true);
}

Run the application.
(3.2 api demos ony) go to the App section.
Go to the Fragment section, and the Tabs section
Switch to the Apps tab.  Wait for it to load.
Switch back to the Simple tab.
Rotate the device (or Ctrl-F12 the emulator)
Switch to the Apps tab. Note the loading spinner comes up and never goes away.

I have tested this on a physical Gingerbread device (2.3.3, which required a bit of hacking on the Support4Demos project to remove android 3.x-specific calls, which someone seems to have just entered as issue 20575), a physical Honeycomb device (3.2.1), and the Honeycomb emulator, and the results were the same.

I would like to know
a) am I doing something wrong?
b) is there a workaround I can do to perform rotations in my tabbed app without discarding data loaded over the internet? c) should I file an issue in http://code.google.com/p/android/issues/list for this behavior? I did a couple searches there, but could not find anything that looked like this.

Thanks,
Jeremy



--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to