title: How to share data between an activity and a fragment using a SharedViewModel?
body: <p>I have an activity class where I have added a fragment using Navigation Components. I have added an <code>OnAuthStateChangeListener</code> in my activity to see when the user is sign-out or not. I have implemented the method like so:</p>
  <pre><code>override fun onAuthStateChanged(isUserSignedOut: Boolean) {
      if (!isUserSignedOut) {
          sharedViewModel.setUid(uid)
      }
  }
  </code></pre>
  <p>My <code>SharedViewModel</code> class looks like so:</p>
  <pre><code>class SharedViewModel @Inject constructor(): ViewModel() {
      val liveData = MutableLiveData&lt;String&gt;()
  
      fun setUid(uid: String) {
          liveData.value = uid
      }
  }
  </code></pre>
  <p>Now in my fragment, I tried to get the uid like so:</p>
  <pre><code>override fun onActivityCreated(savedInstanceState: Bundle?) {
      super.onActivityCreated(savedInstanceState)
      sharedViewModel.liveData.observe(viewLifecycleOwner, Observer&lt;String&gt; { uid -&gt;
          logErrorMessage(&quot;uid: $uid&quot;)
      })
  }
  </code></pre>
  <p>But that observer never fires. I have no output in the logcat whatsoever. How can I get that uid correctly?</p>