用途:
根据指定的URI路径信息返回包含特定数据的Cursor对象,应用这个方法可以使Activity接管返回数据对象的生命周期。
参数:
URI: Content Provider 需要返回的资源索引
Projection: 用于标识有哪些columns需要包含在返回数据中。
Selection: 作为查询符合条件的过滤参数,类似于SQL语句中Where之后的条件判断。
SelectionArgs: 同上。
SortOrder: 用于对返回信息进行排序。
下面是有关 ContentResolver.query() 和 Activity.managedQuery() 两个方法的区别:
To query a content provider, you can use either theContentResolver.query() method or the Activity.managedQuery() method.Both methods take the same set of arguments, and both return a Cursorobject. However, managedQuery() causes the activity to manage the lifecycle of the Cursor. [...]
我也来翻译下:
对于查询一个内容提供者,你可以使用 ContentResolver.query() 或者 Activity.managedQuery() 方法。两种方法都带有相同参数,并且都返回 Cursor 对象。然后,Activity.managedQuery() 方法导致活动管理 Cursor 的生命周期。