admin管理员组文章数量:1392007
I'm using Room in Android with a room .db file with preload data in assets. When I compile and install the app in Android Studio emulator with new data (same schema but more or different data on the tables) in the .db preloaded database of assets floder... the app doesn't display it. It seems that room sees that the database has been already loaded from the .db file previously and doesn't update it. Is there any function or configuration in room necessary to always preload the .db file when it has new data? for example, after an update of the app etc...
I don't want to preserve data, I just want that when an update of the app has come, or the .db file has more or different data, the .db file must be loaded, removing/ovewritting the previous cached database. Is there any built in feature in room to help with this?
For example, specifying that the DB version has been changed, and telling Room that it must remove the cached version and reload the assets .db file. But is that possible? how?
this is my database:
@Database(entities = [
AEntity::class,
BEntity::class,
], version = 1)
abstract class CustomDatabase : RoomDatabase() {
abstract fun customDao(): CustomDao
}
and how I load it:
Room.databaseBuilder(
androidContext(),
CustomDatabase::class.java, "custom-database"
)
.createFromAsset("data.db")
.build()
What I have tryed?
I tryed increasing version = 1)
to 2 and adding .fallbackToDestructiveMigration()
before build()
in the databaseBuilder
, but the result of doing that, is that the app starts with ZERO data, like if the new .db file stored in assets is empty, but is not, it's full of data, I checked it.
本文标签: androidHow to update cached database with assets db file when it has been changedStack Overflow
版权声明:本文标题:android - How to update cached database with assets .db file when it has been changed? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744639096a2617008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论