I am working on an Application where i have to use multi threading. I have a single instance of SQLiteOpenHelper class throughout my application where i have methods to open and close database and some methods to insert and fetch data.
Now my problem is, I open database in First Thread and start transactions at the same time Second Thread also get the opened database object and start transactions.
The First thread complete its process and close the database on the other side my Second thread is working and the Second Thread gets that the database is closed.
Its some logical issue please someone help me to solve this problem how i can handle the closing the database in a proper way.
Thanks in advance
You should only close the database when you are completely done with it, such as when the activity or service that created these threads is destroyed.
It is also not out of the question for you to simply never close the database. If you implement a
ContentProvider, you will never close your database. While this may cause warnings in LogCat about leaking open database handles, SQLite’s transactional nature means that failing to close a database should not cause any particular problems (e.g., failed to flush a buffer).