什么是startManagingCursor的目的是什么? [英] What's the purpose of startManagingCursor?

查看:139
本文介绍了什么是startManagingCursor的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,文档指出,它可以让活动管理指针的生命周期。但我真的没有看到它的点,因为当活动被破坏,新创建的指针的任何引用也应当删除,然后将光标本身留在下次垃圾收集周期灭亡。何必呢?

Ok, the documentation states that it lets the Activity manage the cursor's lifecycle. But I don't really see the point of it since when the activity is destroyed, any references to the newly created cursor should be also erased and then the cursor itself is left to perish in the next garbage collecting cycle. So why bother?

推荐答案

您不应该依赖游标由垃圾回收销毁......光标再presents一个显著的资源量:持有的全部数据由光标,加上连接到内容提供者拥有该光标这也意味着需要其进程被保存在存储器中。

You should not rely on cursors being destroyed by the garbage collector... a cursor represents a significant amount of resources: all of the data held by the cursor, plus the connection to the content provider that owns the cursor which also means requiring that its process be kept in memory.

在Android的较新版本,日志信息打印如果游标的终结运行而不显式关闭,因为它的应用程序的时候与他们进行关闭游标是很重要的。

In more recent versions of Android, log messages are printed if a cursor's finalizer runs without being explicitly closed, because it is important for apps to close cursors when done with them.

管理光标照顾收盘时的活动破坏了游标,但他们做更多的事还有:他们将被停用,重新查询的活动,停止并重新启动

Managed cursors take care of closing the cursor when the activity is destroyed, but they do more than that as well: they will be deactivated and requeried as the activities is stopped and restarted.

这是说,在这一点上,你应该考虑管理游标是德precated。新装载机API是好了很多,而且有很多改进您的应用程序的用户体验 - 它保证所有的游标操作完成关闭主线程(所以没有毛刺在你的UI交互和动画),且能现有的传播在整个活动实例光标数据时的活动是由于配置改变,而不必重新加载数据重新启动。

That said, at this point you should consider managed cursors to be deprecated. The new Loader API is a lot better, and has many improvements to the user experience of your app -- it ensures that all cursor operations are done off the main thread (so there are not glitches in your UI interactions and animations), and can propagate existing cursor data across activity instances when an activity is restarted due to a configuration change instead of having to reload the data.

如果你需要运行在旧版本的Andr​​oid 3.0相比,可使用V4支持库的实现装载机的这些应用程序。

If you need to run on older versions of Android than 3.0, you can use the v4 support library's implementation of Loader for those applications.

这篇关于什么是startManagingCursor的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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