title: Wait for Firestore queries to complete
body: <p>I am currently trying to run multiple queries in firestore and want to wait for them to all complete before executing the next code. I've read up on several possible avenues but I have yet to find a good Android example.</p>
  
  <pre class="lang-java prettyprint-override"><code>public HashMap&lt;String,Boolean&gt; multipleQueries(String collection, String field, final ArrayList&lt;String&gt; criteria) {
  
  HashMap&lt;String,Boolean&gt; resultMap = new HashMap&lt;&gt;();
  
  for (int i = 0; i &lt; criteria.size(); i++){
      final int index = i;
      db.collection(collection).whereEqualTo(field,criteria.get(i)).limit(1)
      .get().addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
  
      @Override
      public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task) {
      if(task.isSuccessful()) {
           if(task.getResult().size() != 0 ){
             resultMap.put(criteria.get(index),true);
           } else {
               resultMap.put(criteria.get(index),false);
            }
      } else {
          resultMap.put(criteria.get(index),false);
  
      }
  
      }
  
       });
     }
     return resultMap;
  
  }
  
  </code></pre>