I get this error: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. It happens when I launch fun turnAllWordsOn() in the ViewModel (code below). This function launches coroutine, and I thought that coroutine always works on the backgroung thread. So why I get this error? Apprecieate any help
In Fragment:
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_turn_all_words_on -> {
viewModel.turnAllWordsOn()
true
}
// othes items
}
In ViewModel:
fun turnAllWordsOn() = viewModelScope.launch {
wordDao.turnAllWordsOn()
}
In Dao:
@Query("UPDATE word_table SET shown = 1")
fun turnAllWordsOn()