现在的位置: 首页 > 综合 > 正文

withValueBackReference简介

2012年12月09日 ⁄ 综合 ⁄ 共 1326字 ⁄ 字号 评论关闭

ContentProviderOperation.Builder的withValueBackReference函数定义如下:

ContentProviderOperation.Builder withValueBackReference(String key,
int previousResult)
Add a ContentValues back reference.
第一个参数key对应于数据库中的列名,第二个参数previousResult代表着:回引数据库批量操作中的第previousResult个数据库操作的返回值。
总的来说就是说把批量数据库操作中的第previousResult个数据库操作的返回值作为列名为key的记录的值
ContentProviderOperation.Builder withValueBackReferences(ContentValues backReferences)
Add a ContentValues of
back references.
同上,只是把2个参数封装成一个参数。

示例1:

 ArrayList<ContentProviderOperation> ops =
         
new ArrayList<ContentProviderOperation>();
 
...
 
int rawContactInsertIndex = ops.size();
 ops
.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
         
.withValue(RawContacts.ACCOUNT_TYPE, accountType)
         
.withValue(RawContacts.ACCOUNT_NAME, accountName)
         
.build());

 ops
.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
         
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
         
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
         
.withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
         
.build());

 getContentResolver
().applyBatch(ContactsContract.AUTHORITY, ops);
 

Note the use of withValueBackReference(String,
int)
 to refer to the as-yet-unknown index value of the raw contact inserted in the first operation.

结束!

抱歉!评论已关闭.