title: Retrieve Current User's Data Firebase?
body: <p>I am having trouble with Firebase, and I'm not sure exactly why. So I've read that it is good practice when using Firebase to grab the current user by their ID, with: <code>FirebaseAuth.getInstance().getCurrentUser().getUid();</code>, and then use a <code>addListenerForSingleValueEvent</code> to grab the data via <code>datasnapshot</code>. Great, in one of my activities, the code worked and I successfully grabbed the data. However, in my other activity the listener is completely ignored according to the debugger...why is this, and how should I fix this? Or, is there a better way?</p>
  
  <p>Here is my activity:</p>
  
  <pre><code>public class GroupActivity extends AppCompatActivity {
  //Tag
  private static String TAG = "GroupActivity";
  
  //Firebase
  private FirebaseDatabase database = FirebaseDatabase.getInstance();
  private DatabaseReference mDatabase = database.getReference("users").child("groups"); //Does Users -&gt; Groups
  private DatabaseReference mRef = FirebaseDatabase.getInstance().getReference().child("users");
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_group);
      ButterKnife.bind(this);
      initializeBottomBar();
  
      //Users from selected list -- previous activity data.
      selectedUsers = (List&lt;UserList&gt;) getIntent().getSerializableExtra("users");
      String groupName = getIntent().getStringExtra("groupName");
  
      //CURRENT USER GOES IN FIRST.
      // TODO : add current user.
      String currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();
      DatabaseReference newRef = mRef.child(currentUserID);
      newRef.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              Log.d(TAG, "Name: " + dataSnapshot.child("name").getValue());
  
              name = String.valueOf(dataSnapshot.child("name").getValue());
              email = String.valueOf(dataSnapshot.child("email").getValue());
              username = String.valueOf(dataSnapshot.child("username").getValue());
              ID = String.valueOf(dataSnapshot.child("uid").getValue());
  
              mCurrentUser.setName(name);
              mCurrentUser.setUsername(username);
              mCurrentUser.setEmail(email);
              mCurrentUser.setUid(ID);
  
              selectedUsers.add(mCurrentUser);
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  
      //ID
      DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
      String uniqueKey = ref.child(currentUserID).child("groups").push().getKey();
  
      //Groups of SelectedUsers!
      SelectedUsers members = new SelectedUsers(groupName, uniqueKey, selectedUsers);
      List&lt;SelectedUsers&gt; groups = new ArrayList&lt;&gt;();
      groups.add(members);
  </code></pre>
  
  <p>Oh, and if you're wondering why I have multiple DatabaseReferences it's because I was testing something to better understand what was going on, that's all.</p>
  
  <p>UPDATE:</p>
  
  <p>I've decided to try debugging <code>selectedUsers.add(mCurrentUsers)</code> by adding a breakpoint while inside of the <code>ValueEventListener</code>, and it shows 2 items, as appropriate.</p>
  
  <p>However, when I debug outside of the <code>ValueEventListener</code> it's missing the current user. Why is this happening?? I've had people suggest trying the <code>mAuthListener</code>, but you cannot grab a datasnapshot so this almost seems useless unless you want the user's email and displayname which firebase holds for you... help? I need the database information NOT the current user's login/authentication information!</p>