title: How to observe data inside viewmodel?
body: <p>I have connect my android application to firebase and am using it to retrieve Authentication details and data from firestone. I am using an MVVM architecture and live data for this. The problem is that I need to retrieve email address first and then used this data to query the firestone which contain documents with ID = emailID. You can see my viewmodel. The value for the emailID is null when every I run this. How can I accomplish this while following the MVVP style of coding ?</p>
  <p>#Edit: I need to understand how can check if the live data has been initialised with a value in the case where one livedata value depends on the other.</p>
  <pre><code>class ProfileViewModel(): ViewModel() {
  
      var random =&quot;&quot;
      private var _name = MutableLiveData&lt;String&gt;()
      val userName
          get()=_name
  
      private  var _post = MutableLiveData&lt;String&gt;()
      val userPost
          get()=_post
  
      private var _imgUrl = MutableLiveData&lt;Uri&gt;()
      val userImgUrl
          get()=_imgUrl
  
      private var _emailId = MutableLiveData&lt;String&gt;()
      val userEmailId
          get()=_emailId
  
  
      init{
  
          getUserDataFromProfile()
          getUserPostFromFirestone()
  
      }
  
      private fun getUserPostFromFirestone() {
  
  
          val mDatabaseInstance: FirebaseFirestore = FirebaseFirestore.getInstance()
  //        _emailId.observe(getApplication(), Observer {
  //
  //        } )
          if(_emailId.value!=null){
              mDatabaseInstance.collection(&quot;users&quot;).document(_emailId.value)
                  .get()
                  .addOnCompleteListener { task -&gt;
                      if (task.isSuccessful) {
                          _post.value = task.result?.data?.get(&quot;post&quot;).toString()
  
                      } else {
  //                    Log.w(&quot;firestone&quot;, &quot;Error getting documents.&quot;, task.exception)
                          _post.value = &quot;Unable to Retrieve&quot;
                      }
                  }
          }
      }
  
      private fun getUserDataFromProfile() {
  
          val mAuth = FirebaseAuth.getInstance()
  
          val currentUser = mAuth.currentUser
          random = currentUser?.displayName!!
          _name.value = currentUser?.displayName
  
          _post.value = &quot;Unknown&quot;
          _imgUrl.value = currentUser?.photoUrl
          _emailId.value = currentUser?.email
  
  
      }
  
  
  }
  </code></pre>