用户
 找回密码
 注册会员
搜索

[APP] withValueBackReference简介

[复制链接]
发表于 2016-6-13 16:13:20
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:
来源http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html
[Java] 纯文本查看 复制代码
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.
结束!




您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

返回顶部