In my application one service is getting data from server and inserting it to table A
.
If I go to particular UI, I need to list data from another
Try to use one SqliteDatabaseHelper and make it single instance. After that don't close the SqliteDatabase instance after complete your operations.
You can implement lock on database for that see this
http://www.sqlite.org/lockingv3.html
When you start a database operation which has many concurrent operation then you have to use
database.beginTransaction(); /* for start transaction */
and after completing operation on database you can use
database.setTransactionSuccessful();
database.endTransaction();
But if you give error in between transaction then don't set database.setTransactionSuccessful();
so that the transaction will be rollback.
Also you can check at the time of error whether currently the database is in transaction or not by database.inTransaction();
if it return true then you are in transaction else you are not in transaction
Also You can check for whether current database has locked or not by calling
database.isDbLockedByCurrentThread();
database.isDbLockedByOtherThreads();
this will return Boolean.
Also you can set whether you want to lock your database if multiple threads are trying to read and write your database at the same time by
database.setLockingEnabled(boolean);
Above deleted methods are deprecated so please do not use.