Class SimpleTarget<Z>
- java.lang.Object
-
- com.bumptech.glide.request.target.BaseTarget<Z>
-
- com.bumptech.glide.request.target.SimpleTarget<Z>
-
- Type Parameters:
Z- The type of resource that this target will receive.
- All Implemented Interfaces:
LifecycleListener,Target<Z>
@Deprecated public abstract class SimpleTarget<Z> extends BaseTarget<Z>
Deprecated.UseCustomViewTargetif loading the content into a view, the download API if in the background (http://bumptech.github.io/glide/doc/getting-started.html#background-threads), or aCustomTargetfor any specialized use-cases. UsingSimpleTargetorBaseTargetis unsafe if the user does not implementBaseTarget.onLoadCleared(android.graphics.drawable.Drawable), resulting in recycled bitmaps being referenced from the UI and hard to root-cause crashes.A simpleTargetbase class with default (usually no-op) implementations of non essential methods that allows the caller to specify an exact width/height. Typically use cases look something like this:Target<Bitmap> target = Glide.with(fragment) .asBitmap() .load("http://somefakeurl.com/fakeImage.jpeg") .apply(fitCenterTransform()) .into(new SimpleTarget<Bitmap>(250, 250) { {@literal @Override} public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { // Do something with bitmap here. } });// At some later point, clear the Target to release the resources, prevent load queues from // blowing out proportion, and to improve load times for future requests: Glide.with(fragment).clear(target); }Warning! this class is extremely prone to mis-use. Use SimpleTarget only as a last resort.
ViewTargetor a subclass ofViewTargetis almost always a better choice.Don't forget to clear instances of this class!. If you must use this class, keep in mind that unlike
ViewTargetit is not safe to load into new instances of this class repeatedly if every instance updates the same underlyingViewor caller. If you need to load into the sameViewor caller repeatedly using this class, always retain a reference to the previous instance and either callRequestManager.clear(Target)on the old instance before starting a new load or you must re-use the old instance for the new load. Glide'sRequestBuilder.into(Target)method returns theTargetinstance you provided to make retaining a reference to theTargetas easy as possible. That said, you must wait until you're completely finished with the resource before callingRequestManager.clear(Target)and you should always null out references to any loaded resources inTarget.onLoadCleared(Drawable).Always try to provide a size when using this class. Use
SimpleTarget(int, int)whenever possible with values that are notTarget.SIZE_ORIGINAL. UsingTarget.SIZE_ORIGINALis unsafe if you're loading large images or are running your application on older or memory constrained devices because it can cause Glide to load very large images into memory. In some cases those images may throwOutOfMemoryErrorand in others they may exceed the texture limit for the device, which will prevent them from being rendered. Providing a valid size allows Glide to downsample large images, which can avoid issues with texture size or memory limitations. You don't have to worry about providing a size in most cases if you useViewTargetso preferViewTargetover this class whenver possible.- See Also:
- Glide's Target docs page
-
-
Field Summary
-
Fields inherited from interface com.bumptech.glide.request.target.Target
SIZE_ORIGINAL
-
-
Constructor Summary
Constructors Constructor Description SimpleTarget()Deprecated.Constructor for the target that usesTarget.SIZE_ORIGINALas the target width and height.SimpleTarget(int width, int height)Deprecated.Constructor for the target that takes the desired dimensions of the decoded and/or transformed resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidgetSize(SizeReadyCallback cb)Deprecated.Immediately calls the given callback with the sizes given in the constructor.voidremoveCallback(SizeReadyCallback cb)Deprecated.Removes the given callback from the pending set if it's still retained.-
Methods inherited from class com.bumptech.glide.request.target.BaseTarget
getRequest, onDestroy, onLoadCleared, onLoadFailed, onLoadStarted, onStart, onStop, setRequest
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.bumptech.glide.request.target.Target
onResourceReady
-
-
-
-
Constructor Detail
-
SimpleTarget
public SimpleTarget()
Deprecated.Constructor for the target that usesTarget.SIZE_ORIGINALas the target width and height.
-
SimpleTarget
public SimpleTarget(int width, int height)Deprecated.Constructor for the target that takes the desired dimensions of the decoded and/or transformed resource.- Parameters:
width- The width in pixels of the desired resource.height- The height in pixels of the desired resource.
-
-
Method Detail
-
getSize
public final void getSize(@NonNull SizeReadyCallback cb)Deprecated.Immediately calls the given callback with the sizes given in the constructor.- Parameters:
cb- The callback that must be called when the size of the target has been determined
-
removeCallback
public void removeCallback(@NonNull SizeReadyCallback cb)Deprecated.Description copied from interface:TargetRemoves the given callback from the pending set if it's still retained.- Parameters:
cb- The callback to remove.
-
-