加载完成后未调用LoaderCallbacks.onLoadFinished() [英] LoaderCallbacks.onLoadFinished() is not called after load finishes

查看:226
本文介绍了加载完成后未调用LoaderCallbacks.onLoadFinished()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从 AsyncTaskLoader 派生的加载器。它在99%的时间内都能正常工作,但是在极端情况下,在 AsyncTaskLoader.loadInBackground() LoaderCallbacks.onLoadFinished() c $ c>成功返回。我不知道在极端情况下有什么不同,但我无法想到加载程序在这两次调用之间失败的任何原因。

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?

推荐答案

首先,重要的是如何运行Loader:

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

您可以通过 activity.getLoaderManager()。initLoader()方法首次运行它,但是您无法运行它

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

您需要进一步使用 activity.getLoaderManager()。restartLoader()方法。您还可以从一开始就使用此方法,因为如果尚未初始化它,它会初始化您的加载器。

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.

强烈建议在Activity的<$中启动加载器。 c $ c> onCreate 方法。

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

如果需要从其他地方启动加载程序,并调用 onLoadFinished 不会发生(例如,旋转屏幕后),请在 onCreate 中调用 getLoaderManager() code>相反,它实际上可以帮助

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.

这篇关于加载完成后未调用LoaderCallbacks.onLoadFinished()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆