This one drove me insane for the longest time. The solution I have found is fairly simple: don’t keep references to SQLiteDatabase
objects. Instead, use a SQLiteOpenHelper
and call getWritableDatabase()
every time you need one. From the docs:
public synchronized SQLiteDatabase getWritableDatabase()
Create and/or open a database that will be used for reading and writing. Once opened successfully, the database is cached, so you can call this method every time you need to write to the database.
The answer was right there the whole time.