I have view model and I use live data. Which one is recommended to use and why? In main thread setValue or in IO thread postValue() or in main thread postValue()
fun getProductInfoFromWebService(barcode: String, url: String) {
viewModelScope.launch(Dispatchers.IO) {
val response = productInfoRepo.getProductInfoFromWebService(barcode, url)
withContext(Dispatchers.Main) {
_productInfoFromWebService.value = response
}
}
}
fun getProductInfoFromWebService(barcode: String, url: String) {
viewModelScope.launch(Dispatchers.IO) {
val response = productInfoRepo.getProductInfoFromWebService(barcode, url)
withContext(Dispatchers.Main) {
_productInfoFromWebService.postValue(response)
}
}
}
fun getProductInfoFromWebService(barcode: String, url: String) {
viewModelScope.launch(Dispatchers.IO) {
val response = productInfoRepo.getProductInfoFromWebService(barcode, url)
_productInfoFromWebService.postValue(response)
}
}