I have search results displayed using ViewPager & FragmentStatePageAdapter, with each set of results in its own fragment. THe data is loaded using a custom AsyncTaskLoader. I want to preserve the scroll position when going to some other activity / to background and coming back.
However, on navigation to another activity and coming back, the Loader Managers calls the onStartLoading() of the loader and unnecessarily reloads the data:
protected void onStartLoading() {
if (results.size() > 0) {
Log.d(TAG, "onStartLoading() - deliver result");
deliverResult(mResults);
}
if (takeContentChanged() || results.size() == 0) {
Log.d(TAG, "onStartLoading() - force load");
// Needed for custom loaders
forceLoad();
}
// Register observer...
}
This also means that I cannot restore the scroll position (saved on fragment's on save). Any way to avoid this reload on fragment's onResume? I am calling the initLoader() only in onActivityCreated(), which is not called when the fragment is restored from the backstack.
I am using the v4 compatibility lib.
Thanks!