Android transactions hang ui thread?
<p>I have the following code:</p>

<pre><code>    Cursor cursor = fetchAllPhoneNumbers();
    mDb.beginTransaction();
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor
                .getColumnIndex(DbAdapter.KEY_CONTACT_ID));
        String phoneNo = cursor.getString(cursor
                .getColumnIndex(DbAdapter.KEY_CONTACT_NO));
        String key = contactId + "," + phoneNo;
        String reg = map.get(key);
        if (reg != null) { 

            updatePhoneNumbersIsRegistered(contactId, phoneNo,
                    reg, System.currentTimeMillis());
        } else {

            deletePhoneNumbersByContactDetail(contactId, phoneNo);
        }
        map.remove(key);

    }

    for (Map.Entry&lt;String, String&gt; pnEntry : map.entrySet()) {
        String pnKey = pnEntry.getKey();
        String pnValue = pnEntry.getValue();
        String[] details = pnKey.split(",");

        createPhoneNumber(details[0], details[1], pnValue,
                System.currentTimeMillis());
    }
    cursor.close();

    mDb.setTransactionSuccessful();
    mDb.endTransaction();
</code></pre>

<p>Running this function in an AsyncTask causes my ui thread to hang until the function is completed, <strong>but if I remove the begin, set and end transaction the ui thread runs freely</strong>, any idea why this is happening or is there a work around? This actually boosted performance from 2 mins to 20 secs when i placed the transaction codes.(Do note it was for testing so i did not do a proper try catch finally to handle the endtransaction.)</p>
