I now finished the android codelab about room db with MVVM arch. But there is one part that i didn't exactly understand. This is a sentence from the codelab:
To delete all content and repopulate the database whenever the app is created, you'll create a RoomDatabase.Callback and override onCreate().
and this is the code they provide:
private class WordDatabaseCallback(
private val scope: CoroutineScope
) : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
INSTANCE?.let { database ->
scope.launch {
populateDatabase(database.wordDao())
}
}
}
suspend fun populateDatabase(wordDao: WordDao) {
// Delete all content here.
wordDao.deleteAll()
}
}
the part that I don't understand is "deleting all content". why do I need to delete all content when the app is created? and what do they mean by "whenever the app is created"? is it for the first time the app installed or everytime app is opened?
when I don't use this code, the app works fine too. can someone explain the purpose of deleting everything?