Search code examples
androiddatabase-migrationandroid-room

Android Room DB: Cannot run invalidation tracker. Is the db closed?


I'm using ROOM DB for Android. I have a same issue with Upgrading Room DB with migrations causes DB lock

My ROOM version is 1.1.1-rc and the problem occurs again. I think there are temporary solutions such as changing DB name, etc. However, it is not the exact solution for migration.

Is there any solution for this problem? Thanks.


Solution

  • Based on the FrameworkSQLiteOpenHelper (which is the default openHelper of Room), custom open helper should not open at onOpen only for migration

    @Override
        public void onOpen(SQLiteDatabase db) {
            if (!mMigrated) {
                // if we've migrated, we'll re-open the db so we  should not call the callback.
                this.mCallback.onOpen(this.getWrappedDb(db));
            }
        }