I'm using Glide to load images and I added a listener to know when resource is ready or if there was an error of any type:

Glide.with(mContext)
    .load(url)
    .placeholder(R.drawable.glide_placeholder)
    // use dontAnimate and not crossFade to avoid a bug with custom views
    .dontAnimate()
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .listener(new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            // do something
            return true;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            // do something
            return true;
         }
    })
    .into(mCustomImageView);

The app never runs inside onResourceReady or onException but if I remove the listener and let the async download without a callback, it runs correctly:

Glide.with(mContext)
    .load(url)
    .placeholder(R.drawable.glide_placeholder)
    // use dontAnimate and not crossFade to avoid a bug with custom views
    .dontAnimate()
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(mCustomImageView);

I tried also with GlideDrawableImageViewTarget instead of listener to receive callbacks but app runs inside onLoadStarted but never runs inside onLoadCleared, onLoadFailed and onResourceReady.


Solution 1:

It seems to be a bug with ImageView's visibility if it's invisible or gone. I opened an issue here: https://github.com/bumptech/glide/issues/618

Solution 2:

Here's one way to do it:

        Glide.with(context).load(...)
                .listener(object : RequestListener<Drawable> {
                    override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
                        //TODO handle error images while loading photo
                        return true
                    }

                    override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                        //TODO use "resource" as the photo for your ImageView
                        return true
                    }

                }).submit()

Solution 3:

Ran into same issue. Having onResourceReady return false did the trick for me.

Solution 4:

You just need to change the return of onResourceReady and onLoadFailed from true to false.

It works for me on glide 4.9.1.

if you look at RequestListener comments you should understand.