ManagedQuery()

用途:
根据指定的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 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() .

例子:

Cursor c = managedQuery(allCalls, null, null, null, null);   
String[] projection = new String[] {      Calls._ID, Calls.NUMBER, Calls.TYPE};   Cursor c = managedQuery(allCalls, projection,      null, null, null); Cursor c = managedQuery(allCalls, projection,      "Calls.NUMBER LIKE '65%'", //---retrieve numbers beginning with 65      null, null); Cursor c = managedQuery(allCalls, projection,      "Calls.NUMBER LIKE '5%'",      null,      "Calls.TYPE DESC"); //---sort result by call TYPE descending  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值