Android DataBase blocked by another thread

I am working on an android sqlite database in which I cannot insert a record into the database.
In the code, I open the database only once during the launch of the application, and I set there a link to my application class variable so that I can access the database from any part of the code, and this works fine.

The problem is that I can access the database, but I cannot start the Transaction. This does not give me an exception, but sqLiteDatabaseWrite.isDbLockedByOtherThreads() returns TRUE . In addition, logcat has one warning message:

WARN / SQLiteDatabase (19006): database lock is not available for 30 seconds. Current owner of the lock: 1. Continuing to wait in the stream: 14

Any solutions?

+4
source share
1 answer

Thank you for being with me. Actually, I solved my problem. I started one SQLite DB operation using sqLiteDatabase.beginTransaction() , and I forgot to finish this transaction. I resolved the issue by completing the transaction. To complete the transaction, I used the following code:

 sqLiteDatabase.setTransactionSuccessful(); sqLiteDatabase.endTransaction(); 

Thanks.

+7
source

Source: https://habr.com/ru/post/1382126/


All Articles