Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
            }
        });
like image 778
Huo Chhunleng Avatar asked Aug 21 '19 03:08

Huo Chhunleng


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) { }
            });
like image 173
Huo Chhunleng Avatar answered Nov 16 '22 22:11

Huo Chhunleng


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) { }
    });
like image 4
Tomas Valenta Avatar answered Nov 16 '22 21:11

Tomas Valenta