且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

片段恢复后,为什么再次调用onLoadFinished?

更新时间:2023-11-01 11:59:22

还有其他类似的问题,例如Android:LoaderCallbacks.OnLoadFinished被调用了两次但是,加载器管理器挂钩的行为是它们的本质。您可以在获得第一组结果后销毁加载程序

There are other similar questions such as Android: LoaderCallbacks.OnLoadFinished called twice However the behavior of the loader manager hooks are what they are. You can either destroy the loader after getting the first set of results

public abstract void destroyLoader (int id)

或者您可以处理onLoaderReset并将您的UI数据与加载器数据更紧密地联系

or you can handle the onLoaderReset and tie your UI data more closely to the loader data

public abstract void onLoaderReset (Loader<D> loader)




在重置先前创建的加载程序时调用,因此
使其数据不可用。应用程序此时应该
删除它对加载程序数据的所有引用。

Called when a previously created loader is being reset, and thus making its data unavailable. The application should at this point remove any references it has to the Loader's data.

我个人而言,我将使用ContentProvider并为此使用一个CursorLoader(每行数据都必须具有唯一的_ID,但对于消息来说应该没有问题)。

Personally, I would use a ContentProvider and a CursorLoader for this (each row of data would need to have a unique _ID but for messages that should not be a problem).