com.bumptech.glide
Class RequestManager

java.lang.Object
  extended by com.bumptech.glide.RequestManager
All Implemented Interfaces:
LifecycleListener

public class RequestManager
extends Object
implements LifecycleListener

A class for managing and starting requests for Glide. Can use activity, fragment and connectivity lifecycle events to intelligently stop, start, and restart requests. Retrieve either by instantiating a new object, or to take advantage built in Activity and Fragment lifecycle handling, use the static Glide.load methods with your Fragment or Activity.

See Also:
Glide.with(android.app.Activity), Glide.with(android.support.v4.app.FragmentActivity), Glide.with(android.app.Fragment), Glide.with(android.support.v4.app.Fragment), Glide.with(Context)

Nested Class Summary
static interface RequestManager.DefaultOptions
          An interface that allows a default set of options to be applied to all requests started from an RequestManager.
 class RequestManager.GenericModelRequest<A,T>
          A helper class for building requests with custom ModelLoaders that requires the user to provide a specific model.
 class RequestManager.ImageModelRequest<T>
          A helper class for building requests with custom ModelLoaders that translate models to InputStream resources for loading images.
 class RequestManager.VideoModelRequest<T>
          A helper class for building requests with custom ModelLoaders that translate models to ParcelFileDescriptor resources for loading video thumbnails.
 
Constructor Summary
RequestManager(Context context, Lifecycle lifecycle, RequestManagerTreeNode treeNode)
           
 
Method Summary
<T> DrawableTypeRequest<T>
from(Class<T> modelClass)
          Returns a request builder that can be used for multiple loads that uses the ModelLoaderFactorys registered for the given model class for InputStreams and ParcelFileDescriptors to load a thumbnail from objects of the given modelClass.
 DrawableTypeRequest<byte[]> fromBytes()
          Returns a request builder that uses StreamByteArrayLoader to load images from byte arrays.
 DrawableTypeRequest<File> fromFile()
          Returns a request builder that uses the ModelLoaderFactory currently registered for File to load the image represented by the given File.
 DrawableTypeRequest<Uri> fromMediaStore()
          Returns a request builder that uses MediaStore.Images.Thumbnails and MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for Uris.
 DrawableTypeRequest<Integer> fromResource()
          Returns a request builder that uses the ModelLoaderFactory currently registered for Integer to load the image represented by the given Integer resource id.
 DrawableTypeRequest<String> fromString()
          Returns a request builder that loads data from Strings using an empty signature.
 DrawableTypeRequest<Uri> fromUri()
          Returns a request builder to load data from Uris using no signature.
 DrawableTypeRequest<URL> fromUrl()
          Deprecated. The URL class has a number of performance problems and should generally be avoided when possible. Prefer load(android.net.Uri) or load(String).
 boolean isPaused()
          Returns true if loads for this RequestManager are currently paused.
 DrawableTypeRequest<byte[]> load(byte[] model)
          Returns a request to load the given byte array.
 DrawableTypeRequest<byte[]> load(byte[] model, String id)
          Deprecated. Use load(byte[]) along with GenericRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be removed in Glide 4.0.
 DrawableTypeRequest<File> load(File file)
          Returns a request builder to load the given File.
 DrawableTypeRequest<Integer> load(Integer resourceId)
          Returns a request builder to load the given resource id.
 DrawableTypeRequest<String> load(String string)
          Returns a request builder to load the given String.
<T> DrawableTypeRequest<T>
load(T model)
          Returns a request builder that uses the ModelLoaderFactorys currently registered for the given model class for InputStreams and ParcelFileDescriptors to load a thumbnail from either the image or the video represented by the given model.
 DrawableTypeRequest<Uri> load(Uri uri)
          Returns a request builder to load the given Uri.
 DrawableTypeRequest<URL> load(URL url)
          Deprecated. The URL class has a number of performance problems and should generally be avoided when possible. Prefer load(android.net.Uri) or load(String).
 DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri)
          Returns a request builder to load the given media store Uri.
 DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri, String mimeType, long dateModified, int orientation)
          Deprecated. Use loadFromMediaStore(android.net.Uri), MediaStoreSignature, and DrawableRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be removed in Glide 4.0.
 void onDestroy()
          Lifecycle callback that cancels all in progress requests and clears and recycles resources for all completed requests.
 void onLowMemory()
           
 void onStart()
          Lifecycle callback that registers for connectivity events (if the android.permission.ACCESS_NETWORK_STATE permission is present) and restarts failed or paused requests.
 void onStop()
          Lifecycle callback that unregisters for connectivity events (if the android.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads.
 void onTrimMemory(int level)
           
 void pauseRequests()
          Cancels any in progress loads, but does not clear resources of completed loads.
 void pauseRequestsRecursive()
          Performs pauseRequests() recursively for all managers that are contextually descendant to this manager based on the Activity/Fragment hierarchy: When pausing on an Activity all attached fragments will also get paused.
 void resumeRequests()
          Restarts any loads that have not yet completed.
 void resumeRequestsRecursive()
          Performs resumeRequests() recursively for all managers that are contextually descendant to this manager based on the Activity/Fragment hierarchy.
 void setDefaultOptions(RequestManager.DefaultOptions options)
          Sets an interface that can apply some default options to all Requests started using this RequestManager.
<T> RequestManager.VideoModelRequest<T>
using(FileDescriptorModelLoader<T> modelLoader)
          Returns a new request builder that uses the given ModelLoader to fetch a ParcelFileDescriptor for loading video thumbnails.
<A,T> RequestManager.GenericModelRequest<A,T>
using(ModelLoader<A,T> modelLoader, Class<T> dataClass)
          Returns a request builder that uses the given ModelLoader to fetch a generic data type.
 RequestManager.ImageModelRequest<byte[]> using(StreamByteArrayLoader modelLoader)
          Returns a request builder that uses the given StreamByteArrayLoader to fetch an InputStream for loading Bitmaps.
<T> RequestManager.ImageModelRequest<T>
using(StreamModelLoader<T> modelLoader)
          Returns a request builder that uses the given StreamModelLoader to fetch an InputStream for loading images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestManager

public RequestManager(Context context,
                      Lifecycle lifecycle,
                      RequestManagerTreeNode treeNode)
Method Detail

onTrimMemory

public void onTrimMemory(int level)
See Also:
ComponentCallbacks2.onTrimMemory(int)

onLowMemory

public void onLowMemory()
See Also:
ComponentCallbacks.onLowMemory()

setDefaultOptions

public void setDefaultOptions(RequestManager.DefaultOptions options)
Sets an interface that can apply some default options to all Requests started using this RequestManager.

Note - These options will be retained for the life the of this RequestManager so be wary of using GenericRequestBuilder.listener(com.bumptech.glide.request.RequestListener)} when starting requests using an Context or Application to avoid leaking memory. Any option that does not use an anonymous inner class is generally safe.

Parameters:
options - The default options to apply to all requests.

isPaused

public boolean isPaused()
Returns true if loads for this RequestManager are currently paused.

See Also:
pauseRequests(), resumeRequests()

pauseRequests

public void pauseRequests()
Cancels any in progress loads, but does not clear resources of completed loads.

See Also:
isPaused(), resumeRequests()

pauseRequestsRecursive

public void pauseRequestsRecursive()
Performs pauseRequests() recursively for all managers that are contextually descendant to this manager based on the Activity/Fragment hierarchy:

Note, on pre-Jelly Bean MR1 calling pause on a Fragment will not cause child fragments to pause, in this case either call pause on the Activity or use a support Fragment.


resumeRequests

public void resumeRequests()
Restarts any loads that have not yet completed.

See Also:
isPaused(), pauseRequests()

resumeRequestsRecursive

public void resumeRequestsRecursive()
Performs resumeRequests() recursively for all managers that are contextually descendant to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics are identical as for pauseRequestsRecursive().


onStart

public void onStart()
Lifecycle callback that registers for connectivity events (if the android.permission.ACCESS_NETWORK_STATE permission is present) and restarts failed or paused requests.

Specified by:
onStart in interface LifecycleListener

onStop

public void onStop()
Lifecycle callback that unregisters for connectivity events (if the android.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads.

Specified by:
onStop in interface LifecycleListener

onDestroy

public void onDestroy()
Lifecycle callback that cancels all in progress requests and clears and recycles resources for all completed requests.

Specified by:
onDestroy in interface LifecycleListener

using

public <A,T> RequestManager.GenericModelRequest<A,T> using(ModelLoader<A,T> modelLoader,
                                                           Class<T> dataClass)
Returns a request builder that uses the given ModelLoader to fetch a generic data type.

Warning - This is an experimental api that may change without a change in major version.

Type Parameters:
A - The type of the model to be loaded.
T - The type of the data to be loaded from the mode.
Parameters:
modelLoader - The ModelLoader class to use to load the model.
dataClass - The type of data the ModelLoader will load.

using

public <T> RequestManager.ImageModelRequest<T> using(StreamModelLoader<T> modelLoader)
Returns a request builder that uses the given StreamModelLoader to fetch an InputStream for loading images.

Type Parameters:
T - The type of the model.
Parameters:
modelLoader - The model loader to use.

using

public RequestManager.ImageModelRequest<byte[]> using(StreamByteArrayLoader modelLoader)
Returns a request builder that uses the given StreamByteArrayLoader to fetch an InputStream for loading Bitmaps.

Parameters:
modelLoader - The byte array loader.

using

public <T> RequestManager.VideoModelRequest<T> using(FileDescriptorModelLoader<T> modelLoader)
Returns a new request builder that uses the given ModelLoader to fetch a ParcelFileDescriptor for loading video thumbnails.

Type Parameters:
T - The type of the model.
Parameters:
modelLoader - The model loader to use.

load

public DrawableTypeRequest<String> load(String string)
Returns a request builder to load the given String. signature.

Parameters:
string - A file path, or a uri or url handled by UriLoader.
See Also:
fromString(), load(Object)

fromString

public DrawableTypeRequest<String> fromString()
Returns a request builder that loads data from Strings using an empty signature.

Note - this method caches data using only the given String as the cache key. If the data is a Uri outside of your control, or you otherwise expect the data represented by the given String to change without the String identifier changing, Consider using GenericRequestBuilder.signature(com.bumptech.glide.load.Key) to mixin a signature you create that identifies the data currently at the given String that will invalidate the cache if that data changes. Alternatively, using DiskCacheStrategy.NONE and/or DrawableRequestBuilder.skipMemoryCache(boolean) may be appropriate.

See Also:
from(Class), load(String)

load

public DrawableTypeRequest<Uri> load(Uri uri)
Returns a request builder to load the given Uri.

Parameters:
uri - The Uri representing the image. Must be of a type handled by UriLoader.
See Also:
fromUri(), load(Object)

fromUri

public DrawableTypeRequest<Uri> fromUri()
Returns a request builder to load data from Uris using no signature.

Note - this method caches data at Uris using only the Uri itself as the cache key. The data represented by Uris from some content providers may change without the Uri changing, which means using this method can lead to displaying stale data. Consider using GenericRequestBuilder.signature(com.bumptech.glide.load.Key) to mixin a signature you create based on the data at the given Uri that will invalidate the cache if that data changes. Alternatively, using DiskCacheStrategy.NONE and/or DrawableRequestBuilder.skipMemoryCache(boolean) may be appropriate.

See Also:
from(Class), loadFromMediaStore(android.net.Uri), loadFromMediaStore(android.net.Uri, String, long, int), GenericRequestBuilder.signature(com.bumptech.glide.load.Key)

loadFromMediaStore

@Deprecated
public DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri,
                                                              String mimeType,
                                                              long dateModified,
                                                              int orientation)
Deprecated. Use loadFromMediaStore(android.net.Uri), MediaStoreSignature, and DrawableRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be removed in Glide 4.0.

Returns a request builder that uses MediaStore.Images.Thumbnails and MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for the given uri if available and uses the given additional data to build a unique signature for cache invalidation.

Parameters:
uri - The uri representing the media.
mimeType - The mime type of the media store media. Ok to default to empty string "". See MediaStore.MediaColumns.MIME_TYPE or MediaStore.MediaColumns.MIME_TYPE.
dateModified - The date modified time of the media store media. Ok to default to 0. See MediaStore.MediaColumns.DATE_MODIFIED or MediaStore.MediaColumns.DATE_MODIFIED.
orientation - The orientation of the media store media. Ok to default to 0. See MediaStore.Images.ImageColumns.ORIENTATION.
See Also:
loadFromMediaStore(android.net.Uri), load(android.net.Uri), GenericRequestBuilder.signature(com.bumptech.glide.load.Key), MediaStoreSignature

loadFromMediaStore

public DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri)
Returns a request builder to load the given media store Uri.

Parameters:
uri - The uri representing the media.
See Also:
fromMediaStore(), load(Object)

fromMediaStore

public DrawableTypeRequest<Uri> fromMediaStore()
Returns a request builder that uses MediaStore.Images.Thumbnails and MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for Uris.

Falls back to the registered ModelLoaderFactory registered for Uris if the given uri is not a media store uri or if no pre-generated thumbnail exists for the given uri.

Note - This method by default caches data using the given Uri as the key. Since content in the media store can change at any time, you should use GenericRequestBuilder.signature(com.bumptech.glide.load.Key) to mix in some additional data identifying the current state of the Uri, preferably using MediaStoreSignature. Alternatively consider avoiding the memory and disk caches entirely using GenericRequestBuilder.diskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) and DiskCacheStrategy.NONE and/or GenericRequestBuilder.skipMemoryCache(boolean).

See Also:
from(Class), loadFromMediaStore(android.net.Uri, String, long, int), load(android.net.Uri), MediaStoreSignature

load

public DrawableTypeRequest<File> load(File file)
Returns a request builder to load the given File.

Parameters:
file - The File containing the image
See Also:
fromFile(), load(Object)

fromFile

public DrawableTypeRequest<File> fromFile()
Returns a request builder that uses the ModelLoaderFactory currently registered for File to load the image represented by the given File. Defaults to StreamFileLoader.Factory and StreamFileLoader to load images from Files.

Note - this method caches data for Files using only the file path itself as the cache key. The data in the File can change so using this method can lead to displaying stale data. If you expect the data in the File to change, Consider using GenericRequestBuilder.signature(com.bumptech.glide.load.Key) to mixin a signature you create that identifies the data currently in the File that will invalidate the cache if that data changes. Alternatively, using DiskCacheStrategy.NONE and/or DrawableRequestBuilder.skipMemoryCache(boolean) may be appropriate.

See Also:
load(java.io.File), from(Class)

load

public DrawableTypeRequest<Integer> load(Integer resourceId)
Returns a request builder to load the given resource id.

Parameters:
resourceId - the id of the resource containing the image
See Also:
fromResource(), load(Object)

fromResource

public DrawableTypeRequest<Integer> fromResource()
Returns a request builder that uses the ModelLoaderFactory currently registered for Integer to load the image represented by the given Integer resource id. Defaults to StreamResourceLoader.Factory and StreamResourceLoader to load resource id models.

By default this method adds a version code based signature to the cache key used to cache this resource in Glide. This signature is sufficient to guarantee that end users will see the most up to date versions of your Drawables, but during development if you do not increment your version code before each install and you replace a Drawable with different data without changing the Drawable name, you may see inconsistent cached data. To get around this, consider using DiskCacheStrategy.NONE via GenericRequestBuilder.diskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) during development, and re-enabling the default DiskCacheStrategy.RESULT for release builds.

See Also:
from(Class), load(Integer), ApplicationVersionSignature, GenericRequestBuilder.signature(com.bumptech.glide.load.Key)

load

@Deprecated
public DrawableTypeRequest<URL> load(URL url)
Deprecated. The URL class has a number of performance problems and should generally be avoided when possible. Prefer load(android.net.Uri) or load(String).

Returns a request builder to load the given URL.

Parameters:
url - The URL representing the image.
See Also:
fromUrl(), load(Object)

fromUrl

@Deprecated
public DrawableTypeRequest<URL> fromUrl()
Deprecated. The URL class has a number of performance problems and should generally be avoided when possible. Prefer load(android.net.Uri) or load(String).

Returns a request builder that uses the ModelLoaderFactory currently registered for URL to load the image represented by the given URL. Defaults to HttpUrlGlideUrlLoader and HttpUrlFetcher to load URL models.

See Also:
from(Class), load(java.net.URL)

load

@Deprecated
public DrawableTypeRequest<byte[]> load(byte[] model,
                                                   String id)
Deprecated. Use load(byte[]) along with GenericRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be removed in Glide 4.0.

Returns a request builder that uses a StreamByteArrayLoader to load an image from the given byte array.

Note - by default loads for bytes are not cached in either the memory or the disk cache.

Parameters:
model - The data to load.
id - A unique id that identifies the image represented by the model suitable for use as a cache key (url, filepath etc). If there is no suitable id, use load(byte[]) instead.
See Also:
load(byte[])

load

public DrawableTypeRequest<byte[]> load(byte[] model)
Returns a request to load the given byte array.

Parameters:
model - the data to load.
See Also:
fromBytes(), load(Object)

fromBytes

public DrawableTypeRequest<byte[]> fromBytes()
Returns a request builder that uses StreamByteArrayLoader to load images from byte arrays.

Note - by default loads for bytes are not cached in either the memory or the disk cache.

See Also:
from(Class), load(byte[])

load

public <T> DrawableTypeRequest<T> load(T model)
Returns a request builder that uses the ModelLoaderFactorys currently registered for the given model class for InputStreams and ParcelFileDescriptors to load a thumbnail from either the image or the video represented by the given model.

Note - for maximum efficiency, consider using from(Class)} to avoid repeatedly allocating builder objects.

Type Parameters:
T - The type of the model to load.
Parameters:
model - The model the load.
See Also:
from(Class)

from

public <T> DrawableTypeRequest<T> from(Class<T> modelClass)
Returns a request builder that can be used for multiple loads that uses the ModelLoaderFactorys registered for the given model class for InputStreams and ParcelFileDescriptors to load a thumbnail from objects of the given modelClass.

Note - you must use DrawableRequestBuilder.load(Object)} to set a concrete model to be loaded before calling GenericRequestBuilder.into(com.bumptech.glide.request.target.Target). You may also use this object for repeated loads by calling request.load(model).into(target). You may also adjust the options after calling DrawableRequestBuilder.load(Object)} and/or GenericRequestBuilder.into(com.bumptech.glide.request.target.Target)}. However, keep in mind that any changes in options will apply to all future loads.

Type Parameters:
T - The type of the model.
Parameters:
modelClass - The class of model requests built by this class will load data from.