I’m getting the following error in an application where I need to access a database from two different threads running in parallel.
java.lang.IllegalStateException: attempt to acquire a reference on a close SQLiteClosable
The problem is that while I do a load on the database in a thread part (for the duration of this process), the user can press any button on the main activity that would modify another table in the same database. Point at which the problem can occur
Is there any way to avoid this error?
thank you very much
Please check out my blog post. It explains how to maintain and share a sqlite database connection and avoid trouble.
http://www.touchlab.co/blog/single-sqlite-connection/
Basically, keep one SQLiteOpenHelper instance in a global singleton, and never “close” it. Its basically just a file reference, and when your app gets closed, the file handle will be closed on its own.