0

I've been studying on how to use Data Binding with Live Data. I understood how to setup data binding with layout and variable instructions in the Layout and how to link up the data binding variable in the Fragment/Activity code.

However, for my Layout Views to respond to LiveData and update themselves when data in my ViewModel changes, you need to do the following:

binding.lifecycleOwner = viewLifecycleOwner

After reading a bit on viewLifecycleOwner I understood that viewLifecycleOwner represent's and is tied to the Fragment's View's lifecycle i.e. from onCreateView() to onDestroyView().

However, what is the lifecycleOwner? Is it the Fragment/Activity's LifeCycleOwner i.e. the LifeCycleOwner that represents the UI Controller's Lifecycle from onStart() to onDestroy().

Also, what happens when we assign the viewLifecycleOwner to binding's lifecycleOwner?

I'm kind of confused. Could somebody simplify this for me? Thanks.

Amey079
  • 131
  • 7

0 Answers0