title: Where should I place viewDataBinding.lifecycleOwner = this.viewLifecycleOwner with Data Binding and Lifecycle?
body: <p>The following code is from the project architecture-samples, you can see it <a href="https://github.com/android/architecture-samples" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I'm not sure where I should place <code>viewDataBinding.lifecycleOwner = this.viewLifecycleOwner</code> between <code>onCreateView()</code> and <code>onActivityCreated()</code>, could you tell me?</p>
  
  <pre><code>class TasksFragment : Fragment() {
  
      private lateinit var viewDataBinding: TasksFragBinding  
  
      override fun onCreateView(
          inflater: LayoutInflater,
          container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          viewDataBinding = TasksFragBinding.inflate(inflater, container, false).apply {
              viewmodel = viewModel
          }
          setHasOptionsMenu(true)
  
          //viewDataBinding.lifecycleOwner = this.viewLifecycleOwner    Can I place here?
          return viewDataBinding.root
      }
  
  
      override fun onActivityCreated(savedInstanceState: Bundle?) {
          super.onActivityCreated(savedInstanceState)
          // Set the lifecycle owner to the lifecycle of the view
          viewDataBinding.lifecycleOwner = this.viewLifecycleOwner    
      }
  
     ..
  }
  </code></pre>