Captcha image cannot be refresh by using Glide

不想你离开。 提交于 2019-11-30 17:08:11

问题


I have tried to use Glide to load an Captcha image into a ImageView. The first time loading is fine. However, when I reload the Captcha image into the same ImageView, the ImageView does not refresh to new image. Does anyone have idea how to solve this issue?

String url = "https://captcha_path";
ImageView imgView = (ImageView)getActivity().findViewById(R.id.imgView);

Glide.with(getActivity()).load(url).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).into(imgView);

回答1:


You can always use Glide.clear() and then call Glide.with(...).load() again. If your url doesn't change when the image changes, you may also need to add .skipMemoryCache(true) to your load call. For more control, check out the .signature() API. You can always do something like:

Glide.with(fragment)
    .load(url)
    .signature(new StringSignature(UUID.randomUUID().toString()))
    .into(imgView);



回答2:


Glide.with(fragment)
    .load(url)
    .signature(new StringSignature(UUID.randomUUID().toString()))
    .into(imgView);

Replace StringSignature with ObjectKey (for Glide v4)

Glide.with(fragment)
        .load(url)
        .signature(new ObjectKey(UUID.randomUUID().toString()))
        .into(imgView);


来源:https://stackoverflow.com/questions/26836489/captcha-image-cannot-be-refresh-by-using-glide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!