title: Firestore - Return a value from a Document Snapshot Java/Android
body: <p>I need to return the value that is retrieved from the document snapshot. I can see the correct value in the LOG but since it is out of scope, and only in onComplete, I cannot access it.<br />
  Can you please help?</p>
  <pre><code>public String getCoEmail() {
      coUserReference = db.collection(&quot;users&quot;).document(email);
    
      coUserReference.get().addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;() {
      @Override
      public void onComplete(@NonNull Task&lt;DocumentSnapshot&gt; task) {
                 if (task.isSuccessful()) {
                 DocumentSnapshot document = task.getResult();
                 if (document.exists()) {
                    String coEmail = document.getString(&quot;coEmail&quot;);
                    Log.d(TAG, &quot;DocumentSnapshot data: &quot; + document.getString(&quot;coEmail&quot;));
                      } else {
                          Log.d(TAG, &quot;No such document&quot;);
                      }
                  } else {
                      Log.d(TAG, &quot;get failed with &quot;, task.getException());
                  }
              }
          });
      return coEmail;
  }
  </code></pre>