managedQuery()与context.getContentResolver.query()与android.provider.something.query() [英] managedQuery() vs context.getContentResolver.query() vs android.provider.something.query()

查看:258
本文介绍了managedQuery()与context.getContentResolver.query()与android.provider.something.query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pretty的简单。 这三者之间的区别是什么?

Pretty simple. What is the difference among those three?

我要列出每个图像的装置。 我应该使用 managedQuery() android.provider.MediaStore.Images.Media.query() context.getContentResolver.query()

I want to list every Image in a device. Should I use managedQuery(), android.provider.MediaStore.Images.Media.query() or context.getContentResolver.query()

推荐答案

managedQuery()将使用ContentResolver的的查询()。所不同的是 与 managedQuery()的活动将继续引用您 光标和关闭它在需要时(在的onDestroy()的实例。)如果 您查询()你自己,你的要管理光标作为 敏感的资源。如果你忘记了,例如,以关闭()的onDestroy(),你会泄漏底层资源(logcat中会警告你 这件事。)

managedQuery() will use ContentResolver's query(). The difference is that with managedQuery() the activity will keep a reference to your Cursor and close it whenever needed (in onDestroy() for instance.) If you do query() yourself, you will have to manage the Cursor as a sensitive resource. If you forget, for instance, to close() it in onDestroy(), you will leak underlying resources (logcat will warn you about it.)

要查询的内容提供商,您可以使用该 ContentResolver.query()法或 Activity.managedQuery()方法。这两种方法都相同的一组参数,并且都返回一个Cursor对象。然而, managedQuery()使管理光标的生命周期的活动。被管理的游标处理所有细微之处,如卸本身当活动暂停,并重新查询自己的活动重新启动时。你可以问一个活动通过调用开始为你管理一个非托管Cursor对象 Activity.startManagingCursor()

To query a content provider, you can use either the ContentResolver.query() method or the Activity.managedQuery() method. Both methods take the same set of arguments, and both return a Cursor object. However, managedQuery() causes the activity to manage the life cycle of the Cursor. A managed Cursor handles all of the niceties, such as unloading itself when the activity pauses, and requerying itself when the activity restarts. You can ask an Activity to begin managing an unmanaged Cursor object for you by calling Activity.startManagingCursor().

更新:

managedQuery 现在去precated(由于Android 3.0)。

managedQuery is now deprecated (as of Android 3.0).

这篇关于managedQuery()与context.getContentResolver.query()与android.provider.something.query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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