title: Wait Firebase async retrieve data in Android
body: <p>I need to store the result of FireBase getValue method that is async by his own. I can't use something like "onPostExecute()" and, for my purpose, i can't execute all my operation "into onDataChange()" because i need some references in future time in other activities.</p>
  
  <p>Here my snippet to retrieve data:</p>
  
  <pre><code>    List&lt;Village&gt; villages = new LinkedList&lt;&gt;();
      Firebase ref = new Firebase("MYFIREBASEURL").child("village");
      ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot snapshot) {
              spinnerArray.clear();
              for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                  Village v = postSnapshot.getValue(Village.class);
                  villages.add(v);
              }
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
              System.out.println("The read failed: " + firebaseError.getMessage());
          }
      });
  </code></pre>
  
  <p>If i try to read villages out of "onDataChange" i have, naturally for his async life, null value. There is a way to ensure that onDataChange was called?.</p>