I\'m trying to trigger an update on LiveData from a coroutine:
object AddressList: MutableLiveData>()
fun getAddressesLiveData(): L
You can do one of the following :
object AddressList: MutableLiveData>()
fun getAddressesLiveData(): LiveData> {
AddressList.value = listOf()
GlobalScope.launch {
AddressList.postValue(getAddressList())
}
return AddressList
}
or
fun getAddressesLiveData(): LiveData> {
AddressList.value = listOf()
GlobalScope.launch {
val adresses = getAddressList()
withContext(Dispatchers.Main) {
AddressList.value = adresses
}
}
return AddressList
}