I'm using a prepopulated Room database in my Android app. After the user logs out, I want to reset the database to its original state (i.e., reload the prepopulated data) so that when a new user logs in, they start with the default dataset.
@Singleton
@Provides
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
return Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"app_database"
).apply {
createFromAsset("database/external_database.db")
fallbackToDestructiveMigration(true)
// Enable multi-instance invalidation (optional)
enableMultiInstanceInvalidation()
}.build()
}