I am trying to download all pictures provided. When all of tasks completed, do something else.
final ArrayList<byte[]> pics = new ArrayList<>();
for(int i=0;i<picUrls.length();i++){
String url = picUrls.getString(i);
Glide.with(this).asBitmap().load(url).apply(new RequestOptions().override(300,300)).listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resource.compress(Bitmap.CompressFormat.PNG, 100, stream);
pics.add(stream.toByteArray());
return false;
}
}).submit();
}
My problem is how to detect all tasks in for loop are completed. Or is there a better way in Glide to download a bunch of images in simple method call?