Try using one SqliteDatabaseHelper and make it a single instance. After that, do not close the SqliteDatabase instance after operations are complete .
You can implement a lock in the database to see this
http://www.sqlite.org/lockingv3.html
When starting an operation with a database that has many simultaneous operations, you should use
database.beginTransaction();
and after completing the database you can use
database.setTransactionSuccessful(); database.endTransaction();
But if you give an error between transactions, then do not set database.setTransactionSuccessful(); so that the transaction is rollback.
You can also check during an error whether the database is currently in a transaction or not, database.inTransaction(); if it returns true, then you are in a transaction, otherwise you are not in a transaction
You can also check if the current database is locked or not by calling
database.isDbLockedByCurrentThread(); database.isDbLockedByOtherThreads();
this will return a boolean value.
You can also set whether you want to lock your database if several threads are trying to read and write your database at the same time.
database.setLockingEnabled(boolean);
The above methods are deprecated, so please do not use.
Dharmendra Aug 05 2018-11-11T00: 00Z
source share