MutableLiveData: Cannot invoke setValue on a background thread from Coroutine

后端 未结 6 1458
说谎
说谎 2020-12-25 10:27

I\'m trying to trigger an update on LiveData from a coroutine:

object AddressList: MutableLiveData>()
fun getAddressesLiveData(): L         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 11:11

    In my case, I had to add Dispatchers.Main to the launch arguments and it worked fine:

     val job = GlobalScope.launch(Dispatchers.Main) {
                        delay(1500)
                        search(query)
                    }
    

提交回复
热议问题