title: How to Detect if Firebase Listeners finished fetching Data?
body: <p>I'm using Firebase ValueEventlistener in an Android app to retreive some data from the database to initialize my UI, but my Problem is that I never know when data fetching is done and it depends on the speed of the user's internet connection, I'm making a delay of 5 seconds for the Listeners to finish fetching data but sometimes it's not enough and data is still null giving a null pointer exception. I want to know when the Firebase Listeners finish fetching data to be able to update my UI .</p>
  
  <p>This is one Method where I fetch Data :</p>
  
  <pre><code>      public void GetRequests(){
  
           Retrieve.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
       Iterable&lt;DataSnapshot&gt; Games = dataSnapshot.getChildren();
  
  
              for(com.google.firebase.database.DataSnapshot game : Games ){
  
                  String Game_Key = game.child("GameKey").getValue(String.class);
                  String Game_Location = game.child("Location").getValue(String.class);
                  String UserID_Sender = game.child("UserID").getValue(String.class);
                  Adapter_Game_Key.add(Game_Key);
                  Adapter_UserID_Sender.add(UserID_Sender);
             }
          }
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  }
  </code></pre>
  
  <p>Here I try to get the data from the Firebase Listeners in an ArrayList to be able to initialize the UI by passing the ArrayLists to an Adapter of a ListView.</p>
  
  <p>Anyone has a solution for this please ?</p>