title: Best approach to waiting on pending live data using architecture components
body: <p>I'm working on an application that fetches data from a graphql server via apollo-android.</p>
  
  <p>I do a single fetch on my aws rds database. I do this fetch right at the <code>onCreate()</code> of my CalendarFragment.</p>
  
  <p>The thing is, at <code>onViewCreated()</code>, I want to set my textview to one of the fields that is fetched, first and last name. So, I run my <code>getBarberFullName</code> method which returns the <code>String</code> value of <code>mBarberFullName</code>. I'm trying to follow the UI controller displays while the view model handles all the logic approach. <code>getBarberFullName</code> resides within my ViewModel.</p>
  
  <pre><code>    public String getBarberFullName() {
          if (appointmentsAreNull()) return mBarberFullName.getValue();
          AppointmentModel am = mMasterAppointments.getValue().get(0);
          String fullName = am.bFirstName;
          fullName = fullName.concat(" " + am.bLastName);
          // Get the logged in barber's full name and set it as mBarberFullName.
          mBarberFullName.setValue(fullName);
          return mBarberFullName.getValue();
      }
  </code></pre>
  
  <p>where <code>mMasterAppointments</code> is a <code>MutableLiveData&lt;List&lt;AppointmentModel&gt;&gt;</code>. In my <code>onViewCreated()</code> callback, I run </p>
  
  <pre><code>String barberName = mBarberViewModel.getBarberFullName();
          mTxtv_barberName.setText(barberName);
  </code></pre>
  
  <p>However, <code>mMasterAppointments</code> is always null so it just returns the default value of mBarberFullName which is a <code>String</code>.</p>
  
  <p>However, if I were to run the following code, in the same <code>onViewCreated()</code>, I get the desired result where the textview is updated with the desired barber's full name.</p>
  
  <pre><code>  mBarberViewModel.getAllAppointments().observe(getViewLifecycleOwner(), am -&gt; {
              if (am.isEmpty()) {
                  Log.d(TAG, "No barber.");
                  return;
              }
              String barberGreeting;
              barberGreeting = am.get(0).bFirstName;
              barberGreeting = barberGreeting.concat(" " + am.get(0).bLastName);
              mTxtv_barberName.setText(barberGreeting);
          });
  </code></pre>
  
  <p><code>getAllAppointments</code> returns an observer to <code>mMasterAppointments</code> located in my ViewModel.   </p>
  
  <p>Although <code>getAllAppointments</code> and <code>getBarberFullName</code> are called within <code>onViewCreated()</code>, one is able to access the pending values of <code>mMasterAppointments</code> while the other is not. Why?</p>
  
  <p>I don't want to do the logic in my Fragments <code>onViewCreated</code> callback, so how can I wait on the pending <code>mMasterApointmentData</code> in my ViewModel's <code>getBarberFullName()</code>? Are there tools within <code>LiveData</code> and <code>ViewModel</code> that would aid me in this situation?</p>