If I return a request by liveData
in a function and observe it in an activity to show the response, will my activity always observe liveData
or only when the function is called?
viewModel:
fun blockContacts(contactList: List<Contact>): LiveData<Resource<Any>> {
val live = MutableLiveData<Resource<Any>>(Resource.loading())
viewModelScope.launch(ioDispatcher) {
mutex.withLock {
...
}
}
return live
}
Activity:
viewModel.blockContacts(checkedList).observe(this) { res ->
...
}