Question

I have this problem every time I use loader. If I start my AsyncTaskLoader and then rotate screen (doesn't matter one or several times) onLoaderFinished() is not called. loadInBackground() finishes its work but onLoaderFinished() is not called. It looks like callbacks are missed but in activity onCreate() I have:

LoaderManager lm = getSupportLoaderManager();
if (lm.getLoader(LOADER_FLIGHTS) != null) {
    lm.initLoader(LOADER_FLIGHTS, null, mFlightsLoaderCallbacks);
}

Doesn't matter callbacks are implemented by activity or field. In my case I use field:

LoaderCallbacks<SearchResult> mFlightsLoaderCallbacks = new LoaderCallbacks<SearchResult>() {

Sometimes it works pretty good but in some devices I have got this trouble again.

I searched in Android bugs tracker but found nothing useful.

Is this my mistake and how can I correct it?

EDIT:

private Handler mHandler = new Handler();

@Override
public void onLoadFinished(Loader<SearchResult> loader, SearchResult res) {
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            dismissProgress(R.string.dlg_wait_flights);
        }
    });
    mResult = res;
    Helper.Log.d(TAG, "Loader.onLoadFinished.");
Was it helpful?

Solution

Don't wrap your initLoader call in an if statement. In fact, I'm not even sure how initLoader is ever called if you are expecting the loader to not be null before you even call initLoader.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top