Interface RequestListener<R>

Type Parameters:
R - The type of resource being loaded.
All Known Implementing Classes:
ExperimentalRequestListener, RequestFutureTarget

public interface RequestListener<R>
A class for monitoring the status of a request while images load.

All methods in this interface will be called from a background thread if the RequestListener is added to a request that is started with RequestBuilder.submit(), RequestBuilder.submit(int, int), or RequestBuilder.into(int, int). Those methods no longer post results back to the main thread to avoid the unnecessary thread interactions and corresponding latency. As a side affect though, listeners added to those requests are no longer called on the main thread. RequestListeners added to requests started with RequestBuilder.into(Target) or RequestBuilder.into(ImageView) will continue to be called back on the main thread.

  • Method Details

    • onLoadFailed

      boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target<R> target, boolean isFirstResource)
      Called when an exception occurs during a load, immediately before Target.onLoadFailed(Drawable). Will only be called if we currently want to display an image for the given model in the given target. It is recommended to create a single instance per activity/fragment rather than instantiate a new object for each call to Glide.with(fragment/activity).load() to avoid object churn.

      It is not safe to reload this or a different model in this callback. If you need to do so use RequestBuilder.error(RequestBuilder) instead.

      Although you can't start an entirely new load, it is safe to change what is displayed in the Target at this point, as long as you return true from the method to prevent Target.onLoadFailed(Drawable) from being called.

      For threading guarantees, see the class comment.

      For example:

      
       public boolean onLoadFailed(Exception e, T model, Target target, boolean isFirstResource) {
           target.setPlaceholder(R.drawable.a_specific_error_for_my_exception);
           return true; // Prevent onLoadFailed from being called on the Target.
       }
       
      Parameters:
      e - The maybe null exception containing information about why the request failed.
      model - The model we were trying to load when the exception occurred.
      target - The Target we were trying to load the image into.
      isFirstResource - true if this exception is for the first resource to load.
      Returns:
      true to prevent Target.onLoadFailed(Drawable) from being called on target, typically because the listener wants to update the target or the object the target wraps itself or false to allow Target.onLoadFailed(Drawable) to be called on target.
    • onResourceReady

      boolean onResourceReady(@NonNull R resource, @NonNull Object model, Target<R> target, @NonNull DataSource dataSource, boolean isFirstResource)
      Called when a load completes successfully, immediately before Target.onResourceReady(Object, com.bumptech.glide.request.transition.Transition).

      For threading guarantees, see the class comment.

      Parameters:
      resource - The resource that was loaded for the target. Non-null because a null resource will result in a call to onLoadFailed(GlideException, Object, Target, boolean) instead of this method.
      model - The specific model that was used to load the image. Non-null because a null model will result in a call to onLoadFailed(GlideException, Object, Target, boolean) instead of this method.
      target - The target the model was loaded into.
      dataSource - The DataSource the resource was loaded from.
      isFirstResource - true if this is the first resource to in this load to be loaded into the target. For example when loading a thumbnail and a full-sized image, this will be true for the first image to load and false for the second.
      Returns:
      true to prevent Target.onResourceReady(Object, Transition) from being called on target, typically because the listener wants to update the target or the object the target wraps itself or false to allow Target.onResourceReady(Object, Transition) to be called on target.