title: How do I pass data out of the onDataChange method?
body: <p>I have a boolean set up to check for duplicate usernames in an app. I want the boolean to return data based on the result of an onDataChange in a ValueEventListener. Here's what I have:</p>
  
  <pre><code>private boolean isUsernameValid(final String username) {
  
  
      mReference = FirebaseDatabase.getInstance().getReference();
      Query query = mReference.child("users").child(username);
      ValueEventListener mListener = new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              if (dataSnapshot.exists()) {
  
                  //create condition that would make isUsernameValid return false
  
              }
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
      };
  
      mReference.addListenerForSingleValueEvent(mListener);
  
      return //if that condition is not met;
  }
  </code></pre>