zihadrizkyef zihadrizkyef - 9 months ago 128
Android Question

Glide : load url as bitmap not working

I want to load bitmap from server using Glide. If it's success then put it in my ImageView then add it to my ArrayList. If it's fail (broken url, no internet, etc) then set ImageView to my default image. But Glide's listener not working at all, also LogCat not show "onException" and "onResourceReady" at all. What's wrong with my code?

.load(MainActivity.URL_SERVER + "/asset/" + imageUrl.getString(i))
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.listener(new RequestListener<String, GlideDrawable>() {
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
ivImage.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.noimage));
return false;
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageLoadedBitmap.add(((GlideBitmapDrawable) resource).getBitmap());
return false;

Answer Source

As of now, nothing in that method chain is actually triggering the image loading operation. You could use .into(ivImage) at the end and just use listener for adding bitmap to array. Or you could use .preload() for more customisation. Also, use .error(R.drawable.noimage) for error image.

Storing bitmaps in an array looks like a bad idea though. If you're loading images in a list, put glide call in your adapter and let glide take care of the catching itself.