Interface RequestListener<R>

    • Method Detail

      • onLoadFailed

        boolean onLoadFailed​(@Nullable
                             GlideException e,
                             java.lang.Object model,
                             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​(R resource,
                                java.lang.Object model,
                                Target<R> target,
                                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.
        model - The specific model that was used to load the image.
        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.