I have a ViewPager with a FragmentStatePagerAdapter. In the onViewCreated method of the ViewPager fragments I call the initLoader method of the LoadManager to start an AsyncTaskLoader like this
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
list = (ListView) view.findViewById(R.id.list);
list.setEmptyView(view.findViewById(R.id.empty));
getLoaderManager().initLoader(0, null, this).forceLoad();
}
The fragment of course implements LoaderCallbacks, find below the implementation of the relevant methods:
@Override
public Loader<List<String>> onCreateLoader(int id, Bundle args) {
logger.debug("Created loader");
return new AsyncTaskLoader<List<String>>(getActivity()) {
@Override
public List<String> loadInBackground() {
return getResults();
}
};
}
@Override
public void onLoadFinished(Loader<List<String>> loader,
List<String> data) {
logger.debug("loader finished");
if (data != null) {
adapter = new CustomListAdapter(getActivity());
list.setAdapter(adapter);
adapter.addAll(data);
}
}
@Override
public void onLoaderReset(Loader<List<String>> loader) {
}
The problem I am having is that for the first page everything works as expected, but for the subsequent pages, I see that the onCreateLoader call is done, the loadInBackground method of the AsyncTaskLoader is called, but the onLoadFinished is not invoked and therefore now results are delivered.
I am using the Android support library.
Does anyone know what am I doing wrong?