title: Master-detail Using ContentResolver.applyBatch()?
body: <p>
  I was wondering if its possible to save master and detail records to a content provider using the android.content.ContentResolver.applyBatch() method in the same operation where subsequent ContentProviderOperation items in the providers parameter depend on the result of previous items.
  </p>
  
  <p>
  The problem I'm having is that the actual Uri isn't known at the time that the ContentProviderOperation.newInsert(Uri) method is called and the Uri is immutable.
  </p>
  
  <p>
  What I have come up with is shown below:
  </p>
  
  <p><P>
  Master Uri: content://com.foobar.masterdetail/master<br/>
  Detail Uri: content://com.foobar.masterdetail/master/#/detail<br/>
  </p></p>
  
  <pre><code>ArrayList&lt;ContentProviderOperation&gt; operations = new ArrayList&lt;ContentProviderOperation&gt;();
  operations.add(ContentProviderOperation.newInsert(intent.getData())
      .withValue(Master.NAME, "")
      .withValue(Master.VALUE, "")
      .build());
  operations.add(ContentProviderOperation.newInsert(intent.getData()
          .buildUpon()
          .appendPath("#") /* ACTUAL VALUE NOT KNOWN UNTIL MASTER ROW IS SAVED */
          .appendPath("detail")
          .build())
      .withValue(Detail.MASTER_ID, /* WHAT GOES HERE? */)
      .withValue(Detail.NAME, "")
      .withValue(Detail.VALUE, "")
      .build());
  ContentProviderResult[] results = this.getContentResolver().applyBatch(MasterDetail.AUTHORITY, operations);
  for (ContentProviderResult result : results) {
      Uri test = result.uri;
  }
  </code></pre>
  
  <p>In my content provider, I am overriding the applyBatch() method in order to wrap the operation in a transaction.</p>
  
  <p>Is this possible or is there a better way to do this?</p>
  
  <p>Thanks.</p>