T C
05/11/2020, 4:31 AMprivate class ClimateDatabaseCallback(
private val scope: CoroutineScope,
private val context: Context
) : RoomDatabase.Callback() {
private val tag = "callback"
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
Log.d(tag, "onOpen called")
}
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
INSTANCE?.let { database ->
Log.d(tag, "MESSAGE 1")
scope.launch {
Log.d(tag, "MESSAGE 2")
//code to populate database
)
}
}
}
}
When running my application after clearing app data, the function is called as expected, but the coroutine I try to launch is skipped, so I will see "MESSAGE 1" but not "MESSAGE 2" in logcat.
What might the problem be?
Edit: Seems to only happen when getDatabase is called from another coroutine and not, say, the init block of a ViewModel.