问题
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