title: addOnSuccesListener execution order problem, firebase storage
body: <p>I have a StorageReference element which stores a folder's reference from firebase and I loop through its elements in order to get every download link, but I don't understand why it's executed in this order. I've done something similar previously and it worked, but now for some reason, I don't understand why, it's not working as it should and why it jumps listeners this way.</p>
  
  <pre><code>private interface FirestoreCallback {
      void onCallback(List&lt;Uri&gt; uris);
  }
  </code></pre>
  
  <pre><code>public ArrayList&lt;Uri&gt; getAllDownloadURIs(final FirestoreCallback firestoreCallback) {
      StorageReference folderPath = ListVideoDates.storage.getReference((String) extra.getSerializable("folderPath"));
      System.out.println("FOLDER PATH: " + folderPath);
  
      final ArrayList&lt;Uri&gt; uris = new ArrayList&lt;&gt;();
  
      folderPath.listAll()
              .addOnSuccessListener(new OnSuccessListener&lt;ListResult&gt;() {
                  @Override
                  public void onSuccess(ListResult listResult) {
                      for (StorageReference file : listResult.getItems()) {
                          file.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
                              @Override
                              public void onSuccess(Uri uri) {
                                  uris.add(uri);
                                  System.out.println("Array inside onSucces2" + uris); // second
                                  // here the array is printed as elements are 
                                  //inserted, but this listener is the last 
                                  //executed listener for some god damn reason
  
                              }
                          });
                      }
                     // firestoreCallback.onCallback(uris);
                  }
              }).addOnSuccessListener(new OnSuccessListener&lt;ListResult&gt;() {
          @Override
          public void onSuccess(ListResult listResult) {
             // firestoreCallback.onCallback(uris);
              System.out.println("Array inside onSucces3" + uris); // first
          }
      });
  
  </code></pre>
  
  <p>Why the first listener executed is the second one and why then it jumps to the f "first" one? I've also tried to insert the callbacks in both locations ( commented above ) and it still doesn't work regardless of the listener order execution, it's still empty when I try to acces it with the method bellow.</p>
  
  <pre><code>public void setAllDownloadURIs() {
      getAllDownloadURIs(new FirestoreCallback() {
          @Override
          public void onCallback(List&lt;Uri&gt; uri) {
              uris = new ArrayList&lt;&gt;(uri);
              System.out.println("URIS inside onCallback: " + uris);
          }
      });
  }
  </code></pre>
  
  <pre><code>   FOLDER PATH: gs://***************************
  W/StorageUtil: no auth token for request
  I/System.out: URI inside setAllDownloadURIs: null
  W/NetworkRequest: no auth token for request
  I/System.out: Array inside onSucces3[]
  W/StorageUtil: no auth token for request
  W/NetworkRequest: no auth token for request
  W/StorageUtil: no auth token for request
  W/NetworkRequest: no auth token for request
  W/StorageUtil: no auth token for request
  W/StorageUtil: no auth token for request
  W/NetworkRequest: no auth token for request
  W/NetworkRequest: no auth token for request
  I/System.out: Array inside onSucces2
  I/System.out: Array inside onSucces2
  I/System.out: Array inside onSucces2
  I/System.out: Array inside onSucces2
  </code></pre>
  
  <p>And here i get 4 array outputs since there are 4 elements in the folder and they're printed as the program is inserting them into the array.</p>