2

So I'm exporting database file to external storage before doing so I'm closing database, and after database is exported I want continue working with this closed database how do I reopen same database without restarting application? If I restart application everything works, but if I just restarting MainActivity where getInstance() method is called and trying to delete something from database app crashes and produces this exception:

android.database.sqlite.SQLiteException: no such table: room_table_modification_log (code 1): , while compiling: DELETE FROM Note WHERE entryid = ?

Im closing database using destroyInstance() method:

companion object {
    private var INSTANCE: MyDatabase? = null

    var lock = Any()

    fun getInstance(context: Context): MyDatabase{
        synchronized(lock){
            if (INSTANCE == null){
                INSTANCE = Room.databaseBuilder(context.applicationContext, MyDatabase::class.java,"MyDB.db").build()
            }
            return INSTANCE!!
        }
    }

    fun destroyInstance() {
        if (INSTANCE?.isOpen == true){
            INSTANCE?.close()
        }

        INSTANCE = null
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
LeTadas
  • 3,436
  • 9
  • 33
  • 65

0 Answers0