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

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

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest