Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is a limitation of <code>ContentProvider</code>. If you are not exposing your data to other applications you can use your custom database adapter implementation with methods and queries straight hitting your requirements.</p> <p><code>bulkInsert()</code> won't help in this situation as it inserts rows only into one table at once. But take a look at <a href="http://developer.android.com/reference/android/content/ContentProvider.html#applyBatch%28java.util.ArrayList%3Candroid.content.ContentProviderOperation%3E%29" rel="nofollow noreferrer">ContentProvider.applyBatch()</a> method and <a href="http://developer.android.com/reference/android/content/ContentProviderOperation.html" rel="nofollow noreferrer">ContentProviderOperation</a>, <a href="http://developer.android.com/reference/android/content/ContentProviderOperation.Builder.html" rel="nofollow noreferrer">ContentProviderOperation.Builder</a> classes (you may need <code>withValueBackReference()</code> for one-to-many inserting).</p> <p>These links should help you understand how to use them:</p> <p><a href="http://www.grokkingandroid.com/better-performance-with-contentprovideroperation/" rel="nofollow noreferrer">http://www.grokkingandroid.com/better-performance-with-contentprovideroperation/</a> <a href="http://www.grokkingandroid.com/androids-contentprovideroperation-withbackreference-explained/" rel="nofollow noreferrer">http://www.grokkingandroid.com/androids-contentprovideroperation-withbackreference-explained/</a> <a href="https://stackoverflow.com/questions/4655291/semantics-of-withvaluebackreference">What are the semantics of withValueBackReference?</a></p> <p>But notice, using <code>ContentProviderOperation</code> is much slower than <code>bulkInsert()</code> if you are inserting many rows at once, as it parses <code>Uri</code> (string comparisions) each time the operation is going to be performed. Doing this way you still have to expose Uri for inserting into child table.</p> <p>If you decide to use <code>applyBatch()</code>, overwrite it in your provider so it performs all operations in one transaction, so you retain consistency in data and speed up database operations:</p> <pre><code>@Override public ContentProviderResult[] applyBatch(ArrayList&lt;ContentProviderOperation&gt; operations) throws OperationApplicationException { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] results = super.applyBatch(operations); db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload