When using a custom AsyncTaskLoader
to download data from a web service, if I press the HOME button in the middle of the loading process and then enter the app again, the onLoadFinished() method is not called. My fragment is calling setRetainInstance(true)
in onActivityCreated()
and it also calls getLoaderManager.initLoader(0, null, this)
in the same method (as is recommended).
While testing, I see that when coming back to the fragment onActivityCreated()
is not called so this may be why onLoadFinished()
is not called. But where else to put the initLoader()
method? I've read in several places that it should not be called in onResume()
.
So, any ideas? I have a lot of loaders in various screens in my app and I need to solve this issue in an elegant way.
After looking at Issue 14944 (http://code.google.com/p/android/issues/detail?id=14944), I solved the issue by overriding
onStartLoading()
in my customAsyncTaskLoader
and callforceLoad()
.An even better solution is to create a custom parent
AsyncTaskLoader
that looks like this (taken from a suggestion by alexvem from the link above):