Simpletarget is deprecated glide?

SimpleTarget has been deprecated since the earlier update of Glide

Glide.with(getActivity()) .load(uri) .asBitmap() .error(R.drawable.no_result) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(final Bitmap bitmap, GlideAnimation glideAnimation) { imageView.setImageBitmap(bitmap); imageView.buildDrawingCache(); } });

2 Answers

Instead of SimpleTarget we use CustomTarget

Glide.with(this) .asBitmap() .load(uri) .error(R.drawable.no_result) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new CustomTarget<Bitmap>() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { imageView.setImageBitmap(resource); imageView.buildDrawingCache(); } @Override public void onLoadCleared(@Nullable Drawable placeholder) { } });

From Glide documentation

Use CustomViewTarget if loading the content into a view, the download API if in the background, or a CustomTarget for any specialized use-cases. Using BaseView is unsafe if the user does not implement BaseTarget.onLoadCleared(android.graphics.drawable.Drawable), resulting in recycled bitmaps being referenced from the UI and hard to root-cause crashes.

This worked for me:

Glide.with(this) .asBitmap() .load(uri) .apply(options) .into(new CustomTarget() { @Override public void onResourceReady(@NonNull Object resource, @Nullable Transition transition) { mBackgroundManager.setBitmap((Bitmap)resource); } @Override public void onLoadCleared(@Nullable Drawable placeholder) { } });

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like