title: Preferred Fragment lifecycle method for instantiating ViewModels
body: <p>In the <a href="https://github.com/googlesamples/android-architecture-components/tree/9acce5ead48dc94539d8f897fddc5a64f33f7eab/GithubBrowserSample" rel="noreferrer">android-architecture-components/GithubBrowserSample</a> repo, the <code>Fragment#onViewCreated</code> lifecycle method is being used for <code>ViewModel</code> instantiation (with the <em><code>Fragment</code>'s</em> scope) for the <code>Fragment</code>s that use the combination of databinding + <code>LiveData</code> + <code>ViewModel</code>:</p>
  
  <p>From <code>SearchFragment.kt</code> of that repo ^:</p>
  
  <pre><code>    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          searchViewModel = ViewModelProviders.of(this, viewModelFactory)
          ...
      }
  </code></pre>
  
  <p>Is there any official guideline or consensus as to which of these <code>Fragment</code> lifecycle methods such as <code>onAttach</code>, <code>onCreate</code>, <code>onViewCreated</code>, or <code>onActivityCreated</code> is the best/safest place to instantiate the <code>Fragment</code>'s <code>ViewModel</code> using the <code>ViewModelProviders.of(fragment, viewModelFactory)</code> method? (given the databinding + <code>LiveData</code> combo, if that makes a difference)</p>
  
  <p>Trying to make sense of the general advantages/disadvantages of putting <code>ViewModel</code> instantiation into any of the early lifecycle methods such as <code>onAttach</code>/<code>onCreate</code>, for example (after calling <code>super</code>, of course).</p>
  
  <p>Thanks in advance.</p>