title: How to return DataSnapshot value as a result of a method?
body: <p>I don't have much experience with Java. I'm not sure if this question is stupid, but I need to get a user name from Firebase realtime database and return this name as a result of this method. So, I figured out how to get this value, but I don't understand how to return it as result of this method. What's the best way to do this?</p>
  
  <pre><code>private String getUserName(String uid) {
      databaseReference.child(String.format("users/%s/name", uid))
              .addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              // How to return this value?
              dataSnapshot.getValue(String.class);
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {}
      });
  }
  </code></pre>