ConcurrentModificationException crashes my app
<p>My Android app has an IntentService where it requests a list of MessageThreads objects from Facebook, parses the JSON response to build an ArrayList of the objects:</p>

<pre><code>ArrayList&lt;MessageThread&gt; mMessageThreads = new ArrayList&lt;MessageThread&gt;();
</code></pre>

<p>Then it calls FB again in the same service, get the names for the MessageThread ids and matches them with the MessageThread objects. At this point I have an ArrayList with complete MessageThread objects and I insert them into an SQLite db.</p>

<pre><code>// save to db and broadcast
for (MessageThread message : mMessageThreads) {
    ((FBClientApplication)getApplication()).getMessagesData().insertOrIgnore(message.toContentValues();
}
</code></pre>

<p>where:</p>

<pre><code>public void insertOrIgnore(ContentValues values) {
    SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    db.insertWithOnConflict(TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
}
</code></pre>

<p>Via ACRA reports I see that intermittently the line</p>

<pre><code>for (MessageThread message : mMessageThreads) 
</code></pre>

<p>throws an <code>ConcurrentModificationException</code> and the app forcloses. I haven't been able to isolate under what conditions. I read about this <code>Exception</code> and as I understand it it happens when we remove items from an <code>ArrayList</code> while iterating over it, but I'm not removing items from the list. Any pointers to help with this problem are greatly appreciated.</p>
