Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:05:50+00:00 2026-05-23T19:05:50+00:00

I cannot figure out the exact semantics of withValueBackReference . I’ve read the example

  • 0

I cannot figure out the exact semantics of withValueBackReference.

I’ve read the example code (for example the code which adds a new contact) using this method, providing a backReference value of 0. What does this mean?

The documentation says:

A column value from the back references takes precedence over a value specified in withValues(ContentValues)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:05:51+00:00Added an answer on May 23, 2026 at 7:05 pm

    This question relates to batch operation on a content provider. The example is modified from this related question.

    When creating a batch of operations first create a list of operations to perform using:

    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    

    then apply them to the content provider using the applyBatch method.

    ContentProviderResult[] results = this.getContentResolver().applyBatch(FooBar.AUTHORITY, operations);
    

    That is the basic concept so let’s apply it. Suppose we have a content provider which handles uris for Foo records and some child records called Bar.

    content://com.stackoverflow.foobar/foo

    content://com.stackoverflow.foobar/foo/#/bar

    For now we’ll just insert 2 new Foo recordscalled "Foo A" and "Foo B", here’s the example.

    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    
    //add a new ContentProviderOperation - inserting a FOO record with a name and a decscription
    operations.add(ContentProviderOperation.newInsert(intent.getData())
        .withValue(FOO.NAME, "Foo A")
        .withValue(FOO.DESCRIPTION, "A foo of impeccable nature")
        .build());
    
    //let's add another
    operations.add(ContentProviderOperation.newInsert(intent.getData())
        .withValue(FOO.NAME, "Foo B")
        .withValue(FOO.DESCRIPTION, "A foo of despicable nature")
        .build());
    
    ContentProviderResult[] results = this.getContentResolver().applyBatch(FooBar.AUTHORITY, operations);
    

    Nothing special here, we are adding 2 ContentProviderOperation items to our list and then applying the list to our content provider. The results array filled with the id’s of the new records that we have just inserted.

    So say we wanted to do something similar but we also want to add some child records into our content provider in one batch operation. We want to attach the child records to the Foo records we just created. The problem is we don’t know the id of the parent Foo records because the batch has not been run. This is where the withValueBackReference helps us. Let’s see an example:

    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    
    //add a new ContentProviderOperation - inserting a Foo record with a name and a decscription
    operations.add(ContentProviderOperation.newInsert(intent.getData())
        .withValue(FOO.NAME, "Foo A")
        .withValue(FOO.DESCRIPTION, "Foo of impeccable nature")
        .build());
    
    //let's add another
    operations.add(ContentProviderOperation.newInsert(intent.getData())
        .withValue(FOO.NAME, "Foo B")
        .withValue(FOO.DESCRIPTION, "Foo of despicable nature")
        .build());
    
    //now add a Bar record called [Barbarella] and relate it to [Foo A]
    operations.add(ContentProviderOperation.newInsert(intent.getData()
        .buildUpon()
        .appendPath("#") /* We don't know this yet */
        .appendPath("bar")
        .build())
    .withValueBackReference (BAR.FOO_ID, 0) /* Index is 0 because Foo A is the first operation in the array*/
    .withValue(BAR.NAME, "Barbarella")
    .withValue(BAR.GENDER, "female")
    .build());
    
    //add a Bar record called [Barbarian] and relate it to [Foo B]
    operations.add(ContentProviderOperation.newInsert(intent.getData()
        .buildUpon()
        .appendPath("#") /* We don't know this yet */
        .appendPath("bar")
        .build())
    .withValueBackReference (BAR.FOO_ID, 1) /* Index of parent Foo B is 1*/
    .withValue(BAR.NAME, "Barbarian")
    .withValue(BAR.GENDER, "male")
    .build());
    
    ContentProviderResult[] results = this.getContentResolver().applyBatch(FooBar.AUTHORITY, operations);
    

    So the withValueBackReference() method allows us to insert the related records before we know the id of the parent we want to relate them to. The back reference index is simply the index of the operation that will return the id we want to look for. It is perhaps easier to think of it in terms of which result you would expect to contain the id. e.g results[1] would contain the id for "Foo B" so the index we use to back reference to "Foo B" is 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot figure out how to write the following query using the DbFinderPlugin 1.2.2
I cannot figure out how to convert this code from C# to VB.net. It
I cannot figure out why it's throwing a NullPointerException on line 28, which is
I cannot figure out how to merge the following separate pieces of code: $(document).ready(function
I cannot figure out how to change the title bar icon (the icon in
I cannot figure out a way to disable a container AND its children in
I cannot figure out how to enable per-session instances for my WCF service while
I cannot figure out how to make a C# Windows Form application write to
I cannot figure out why I get this error during check-in. I checked in
I cannot figure out what my object instance names are because of how I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.