Skip to content Skip to sidebar Skip to footer

Async Task Could Not Keep Up With For Loop (firebase)

for (Uri mUri : mSelected) { imagesRef = storageRef.child(postid + mUri.getLastPathSegment()); imagesRef.putFile(mUri).addOnSuccessListener(task4 -> d

Solution 1:

I think the problem might be with imagesRef, it is declared outside of for (Uri mUri : mSelected) {...} and therefore it is being replaced before addOnSuccessListener(...) responds.

So, declare it locally to for (Uri mUri : mSelected) {...} and see if it will not resolve the issue. Like this

for (Uri mUri : mSelected) 
{
       var imagesRef = storageRef.child(postid + mUri.getLastPathSegment());
       imagesRef.putFile(mUri).addOnSuccessListener(task4 ->
       db.collection("posts").document(postid).update("photo_id", FieldValue.arrayUnion(imagesRef.getDownloadUrl())));
 }

Post a Comment for "Async Task Could Not Keep Up With For Loop (firebase)"