我必须使用 Fragments 来获取 LoaderManager 吗?
根据一些文档,我可以在 Activity 或 Fragment 中使用 Loader,但兼容性包显示只有 FragmentActivity 具有 getLoaderManager() 方法。
由于旧的托管游标已被弃用,我们必须使用游标加载器。那么为什么这个数据管理功能应该与 UI 小部件的选择联系在一起呢?这对我来说毫无意义。
谢谢 P。
According to some of the documentation I can use a Loader in either an Activity or a Fragment but the Compatibility Package is showing that only a FragmentActivity has the getLoaderManager() method.
Since the old managed cursor has been deprecated we have to use the Cursor Loader. So why should this data management function be tied to a choice of UI widgets ? It makes no sense to me.
thanks
P.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,托管游标仍然有效。通常,Android 中的“已弃用”意味着“我们将尽可能支持此机制,但我们认为还有更好的选择”。
它不是。您不必使用片段来继承
FragmentActivity
。也欢迎您创建自己的LoaderManagerCapableActivity
,您可以在其中从FragmentActivity
克隆相关数据成员和方法(源代码位于您的硬盘上)。但是,LoaderManager
必须与某个活动关联,因为它与活动生命周期相关联,托管游标也是如此。例如,LoaderManager
实例通过onRetainNonConfigurationInstance()
在活动之间传递。No, managed cursors still work. Usually, "deprecated" in Android means "we will support this mechanism as long as we can, but we think there are better options".
It's not. You do not have to use fragments to inherit from
FragmentActivity
. You are also welcome to create your ownLoaderManagerCapableActivity
, where you clone the relevant data members and methods fromFragmentActivity
(the source code is on your hard drive). However,LoaderManager
has to be associated with an activity, because it is tied into the activity lifecycle, as are the managed cursors. For example, theLoaderManager
instances are passed between activities viaonRetainNonConfigurationInstance()
.是的,为了获取 loaderManager,它必须与一个活动相关联,但是可以使用加载器而不需要 loaderManger。
1) 实现AsynTaskLoader。
2) 实例化您在类中实现的 Loader。
3) 为您的加载器注册一个监听器,以便在加载完成后您将收到回调。
4)调用加载器的startLoading方法。
5) 加载完成后,将调用回调方法,您可以将加载的数据用于任何目的。
Yes, inorder to get loaderManager it must be associated with an a activity however it is possible to use loaders without the need of loaderManger.
1) Implement the AsynTaskLoader.
2) Instantiate the Loader you implemented in your class.
3) Register a listener for your loader so that you will get the callback once the load is complete.
4) Call the startLoading method of the loader.
5) After the load is complete the callback method will be called where you can use the loaded data for any purpose.