jeudi 23 juillet 2015

Content Provider wirting to database while SimpleCursorAdapter reads from same table

I'm having trouble with the SQLite database in Android.

I've implemented a Content Provider and throught the app this works just perfect.

At several points within the app i have lists which implements a LoaderManager together with a SimpleCursorAdapter. And this works fine, too.

Now I have a background thread which updates (meaning update, insert and delete) data in the db.

As long as the user is not on an activity/fragment which implements a list (as described above) everything works fine.

But in case the user is on such a list activty/fragment I get the following exception:

java.lang.IllegalStateException: database not open
net.sqlcipher.database.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1593)
net.sqlcipher.database.SQLiteDatabase.insert(SQLiteDatabase.java:1510)
...ContentProvider.insert(ContentProvider.java:297)

it points to the db.udapte(...) statement within the Content Provider.

My assumption is, that I get this error because the SimpleCursorAdapter has an opean (readable) pointer to the table, hence it's locked.

How can I solve this issue?

And yes, I'm using SQLCipher. But I'm also experiencing this problem with the default Andoird implementation.

Aucun commentaire:

Enregistrer un commentaire