I am using live data in my application for all the network calls and response handling.
In one of the scenarios, my recycler view is loading some data in its view holder's onBind
and the response is updating the UI. In order to do so, I have to provide a lifecycleOwner
to the observer.
As recycler view doesn't have any lifecycle owner of its own, I am using the parent fragment for that by using parentFragment.viewlifecycleOwner
but somehow it is giving an error.
How can a view Holder have its instance when the parent fragment is not having its instance?
viewModel.responseState.observe(parentFragment.viewLifecycleOwner, Observer {
updateUI(it)
})
Fatal Exception: java.lang.IllegalStateException: Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()