Answer the question
In order to leave comments, you need to log in
Why do LiveData listeners in the ViewModel fire when the screen configuration changes?
There is a fragment that holds a reference to the ViewModel. Inside the ViewModel there are several fields of type LiveData, with data.
The fragment's OnCreateView() has listeners on the LiveData of our ViewModel.
For example this one:
viewModel.networkState.observe(viewLifecycleOwner, Observer {
when(it){
NetworkState.LOADING -> activityContract.showProgressBar()
NetworkState.LOADED -> activityContract.hideProgressBar()
NetworkState.NO_INTERNET ->activityContract.showErrorDialog(NetworkState.NO_INTERNET.msg)
NetworkState.ERROR -> activityContract.showErrorDialog(NetworkState.ERROR.msg)
NetworkState.API_LIMIT_EXCEEDED -> activityContract.showErrorDialog(NetworkState.API_LIMIT_EXCEEDED.msg)
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question