I am implementing Android Architecture Components
. Imagine a case like the following where your Fragment
is observing a LiveData
to change its UI. User minimizes the app and the state is changed (in my case from the repository). So the Observer
from the Fragment
is not triggered with a change because the Fragment
is not visible. But then, when the user comes back to the app it doesn't trigger the new state. If the state is changed again (while the Fragment
is visible), the Observer
receives the change. Do you know any way to force an update when fragment is visible again?
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
vm = ViewModelProviders.of(this, viewModelFactory).get(MyViewModel::class.java)
vm.getStatus()?.observe(this, Observer<MyRepository.Status> { status ->
if (status != null) {
when (status) {
NONE -> setNoneUI()
LOADING -> setLoadingUI()
CONTENT -> setContentUI()
ERROR -> setErrorUI()
}
}
})
}