title: Android ViewModel reference Fragment
body: <p>I'm a beginner android dev and am looking to write a fully jetpack app. I'm wondering the best way to communicate with the fragment from the ViewModel to say, show a dialog, or navigate to another fragment.</p>
  
  <p>I had something like this:</p>
  
  <pre><code>class Foo: ViewModel() {
  
      interface Callbacks {
          fun doSomethingWithUI()
          fun showBaz()
      }
  
      var callbacks: Callbacks? = null
  }
  </code></pre>
  
  <p>And then in the fragments onCreate it would set itself as the viewmodels callbacks object.</p>
  
  <p>Looking at the documentation it states that the ViewModel shouldn't hold onto anything related view or lifecycle, or that has a reference to the activity. Thinking on this the ViewModel is referencing the fragment that has the activity. </p>
  
  <p>I'm wondering, why is this bad. Everything seems to be working correctly and if there only ever was one activity to begin with, what would we ever be leaking? Why does google make it very clear not to hold onto these things but never really says why not to. </p>
  
  <p>Also, since what I am doing is not ok, what is the "correct" way for having the ViewModel tell the fragment to say, "show a dialog with this error"</p>