Remove All Ads from XDA
Honor View 10

Getting ANR in concurrent DB access

1 posts
Thanks Meter: 0
By gauravAgrawal34, Junior Member on 14th March 2014, 05:37 PM
Post Reply Email Thread
I have used content provider in my project and override the applyBatch() for writting data into the database :

public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final Context context = getContext();
final SQLiteDatabase db = getDatabase(context);
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
return results;
} finally {

If there is any writing operation to the database, applyBatch() method get called and in same time if I will make query from database(using CursorLoader), or call apply batch from different activity ANR comes and the following exception will also comes :

W/SQLiteConnectionPool(18025): The connection pool for database '' has been unable to grant a connection to thread 8073 (pool-17-thread-3) with flags 0x2 for 64.105 seconds.
W/SQLiteConnectionPool(18025): Connections: 0 active, 1 idle, 0 available.

The above issue will not come if I remove the methode db.beginTrasaction() and db.endTrasaction() from applyBatch(). But in that case reading/writing time becomes large. I have used methods db.beginTrasaction() and db.endTrasaction() which reduces database access time to ten times.

Is there any approach, so that SQLite DataBse response quickly and there is no ANR ?
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes