Class RequestFutureTarget<R>

java.lang.Object
com.bumptech.glide.request.RequestFutureTarget<R>
Type Parameters:
R - The type of the resource that will be loaded.
All Implemented Interfaces:
LifecycleListener, FutureTarget<R>, RequestListener<R>, Target<R>, Future<R>

public class RequestFutureTarget<R> extends Object implements FutureTarget<R>, RequestListener<R>
A Future implementation for Glide that can be used to load resources in a blocking manner on background threads.

Note - Unlike most targets, RequestFutureTargets can be used once and only once. Attempting to reuse a RequestFutureTarget will probably result in undesirable behavior or exceptions. Instead of reusing objects of this class, the pattern should be:


 FutureTarget<File> target = null;
 RequestManager requestManager = Glide.with(context);
 try {
   target = requestManager
      .downloadOnly()
      .load(model)
      .submit();
   File downloadedFile = target.get();
   // ... do something with the file (usually throws IOException)
 } catch (ExecutionException | InterruptedException | IOException e) {
   // ... bug reporting or recovery
 } finally {
   // make sure to cancel pending operations and free resources
   if (target != null) {
     target.cancel(true); // mayInterruptIfRunning
   }
 }
 
The cancel(boolean) call will cancel pending operations and make sure that any resources used are recycled.
  • Constructor Details

    • RequestFutureTarget

      public RequestFutureTarget(int width, int height)
      Constructor for a RequestFutureTarget. Should not be used directly.
  • Method Details