LoaderCallbacks.onLoadFinished() is not called after load finishes

余生长醉 提交于 2019-12-06 08:47:25

问题


I created a loader that descends from AsyncTaskLoader. It works 99% of the time, but there's an edge case where LoaderCallbacks.onLoadFinished() is not called after AsyncTaskLoader.loadInBackground() returns successfully. I don't know what's different in the edge case but I can't think of any reason why the loader would fail between these two calls. Is there anything I could be doing wrong?


回答1:


First of all, it is important how you run your Loader:

You can run it first time by activity.getLoaderManager().initLoader() method, but you can't run it second time like this.

You need to use activity.getLoaderManager().restartLoader() method for further. You also can use this method right from the start, because it will init your loader if it was not initialized yet.

It is highly recommended to start loaders in Activity's onCreate method.

If you need to start your loader from somewhere else, and call to onLoadFinished does not happen (for example, after you rotate the screen), place call to getLoaderManager() in onCreate instead, it can really help.



来源:https://stackoverflow.com/questions/31413584/loadercallbacks-onloadfinished-is-not-called-after-load-finishes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!