LoaderCallbacks.onLoadFinished not called if orientation change happens during AsyncTaskLoader run

Nikolay identified the issue – Thank you.

I was calling initLoader fron onResume(). The Android documentation states:

“You typically initialize a Loader within the activity’s onCreate()
method, or within the fragment’s onActivityCreated() method.”

Read “typically” as a bit more emphatic than I did when it comes to dealing with configuration change life cycle.

I moved my initLoader call to onCreate() and that solved my problem.

I think the reason is that in FragmentActivity.onCreate() a collection of LoaderManagers is pulled from LastNonConfigurationInstance and in FragmentActivity.onStart() there is some start up work regarding Loaders and LoaderManagers. Things are already in process by the time onResume() is called. When the Loader needs instantiated for the first time, calling initLoader from outside onCreate() still works.

Leave a Comment