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
RequestListeneris added to a request that is started withRequestBuilder.submit(),RequestBuilder.submit(int, int), orRequestBuilder.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.RequestListenersadded to requests started withRequestBuilder.into(Target)orRequestBuilder.into(ImageView)will continue to be called back on the main thread.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanonLoadFailed(GlideException e, java.lang.Object model, Target<R> target, boolean isFirstResource)Called when an exception occurs during a load, immediately beforeTarget.onLoadFailed(Drawable).booleanonResourceReady(R resource, java.lang.Object model, Target<R> target, DataSource dataSource, boolean isFirstResource)Called when a load completes successfully, immediately beforeTarget.onResourceReady(Object, com.bumptech.glide.request.transition.Transition).
-
-
-
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 beforeTarget.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 toGlide.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
Targetat this point, as long as you returntruefrom the method to preventTarget.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 maybenullexception containing information about why the request failed.model- The model we were trying to load when the exception occurred.target- TheTargetwe were trying to load the image into.isFirstResource-trueif this exception is for the first resource to load.- Returns:
trueto preventTarget.onLoadFailed(Drawable)from being called ontarget, typically because the listener wants to update thetargetor the object thetargetwraps itself orfalseto allowTarget.onLoadFailed(Drawable)to be called ontarget.
-
onResourceReady
boolean onResourceReady(R resource, java.lang.Object model, Target<R> target, DataSource dataSource, boolean isFirstResource)
Called when a load completes successfully, immediately beforeTarget.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- TheDataSourcethe resource was loaded from.isFirstResource-trueif 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 betruefor the first image to load andfalsefor the second.- Returns:
trueto preventTarget.onResourceReady(Object, Transition)from being called ontarget, typically because the listener wants to update thetargetor the object thetargetwraps itself orfalseto allowTarget.onResourceReady(Object, Transition)to be called ontarget.
-
-