So in some rare instances, I\'m seeing the \"attempt to write a readonly database\" message, and I can\'t figure out where the problem lies. I\'ll start with the stacktrace
I'm stuck with more or less the exact same issue and I found a an open defect on the matter that makes sense...
https://code.google.com/p/android/issues/detail?id=174566
My workaround - albeit not the best solution - is to never step the database revision and track this myself, thus never calling onUpgrade()
, and manually do an upgrade when updating the app.
Alternatively if you have a small DB which is read only, you can trigger the copy of the db in assets on every onCreate()
in DBHelper
class, but this might give unwanted problems if the filesystem is full so only do this whilst looking for a better solution.
@Override
public void onCreate(SQLiteDatabase db) {
// Workaround for Issue 174566
myContext.deleteDatabase(DB_NAME);
try {
copyDataBase();
}
catch(IOException e) {
System.out.println("IOException " + e.getLocalizedMessage());
}
}
My app now upgrades as it should with my workaround and by judging how long time it is since this defect was raised originally it might never be fixed at all...
I'm sorry this isn't a full solution to the problem, but it's a way forward at least.