When I update an item it says Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
The app uses Jetpack compose.
I have a function in my DAO used to update an item
@Update
fun update(item:Item)
And a repository to access the database
fun update(item:Item){
itemDao.update(item)
}
In my viewmodel, I use viewModelScope to call the function
fun update(item: Item){
viewModelScope.launch {
itemRepository.update(item)
}
}
However, when I call itemViewModel.update(item)
in an onclick()
scope, the error still occurs which I dont know why.