gpt4 book ai didi

android - `LoaderManager.restartLoader` 是否创建了一个新对象?

转载 作者:行者123 更新时间:2023-11-30 00:19:06 28 4
gpt4 key购买 nike

restartLoader(int id, Bundle args, LoaderCallbacks<D> callback)创建一个全新的加载器对象?或者它只是通过重置其内部状态来重用旧的?

感谢您的帮助。

最佳答案

如果每次调用都传递相同的ID

 restartLoader(int id, Bundle args, LoaderCallbacks<D> callback)

它将重用相同的加载器对象。但是,如果您传递一个新的 ID,它将创建一个新的 Loader 对象。其工作方式来自文档检查 this quote from the documentation :

Starts a new or restarts an existing Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it. If a loader with the same id has previously been started it will automatically be destroyed when the new loader completes its work. The callback will be delivered before the old loader is destroyed.

但是您不必对此进行深入研究,因为 ID 是本文档指南中的重要内容,check the Loader Summary Here :

To start loading data from a loader, call either initLoader() or restartLoader(). The system automatically determines whether a loader with the same integer ID already exists and will either create a new loader or reuse an existing loader.

简而言之,如果您传递不同的 ID,它将创建一个新的加载器,但如果您传递相同的 ID,它将使用相同的加载器。但请记住,游标 不会重复使用。

关于android - `LoaderManager.restartLoader` 是否创建了一个新对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46639376/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com