Android:图像未在 ImageView 上更新,但它每天在 URL(source.unsplash.com/daily) 上更新

Android: Image not updating on ImageView however its updated daily on URL(source.unsplash.com/daily)

我正在使用来自 https://source.unsplash.com/daily?nature
的 Glide 将图像加载到我的应用程序 这是一个免费使用的图片平台,上面的 link 每天更新图片。

但是,Glide 显示的是旧的缓存图像,即使该图像已在网站上更新。

使用的代码:

Glide.with(this)
             .load("https://source.unsplash.com/daily?nature")
             .into(imageView);

滑行版本:4.0.0

像这样更改您的代码。

Glide.with(this)
        .load("https://source.unsplash.com/daily?nature")
        .signature(new StringSignature(yourVersionMetadata))
        .into(imageView);

希望它能解决您的问题。有关详细信息,请参阅 here

如果你的 URL 相同并且 catch 在 glid 中是正确的,那么它会从你第一天选择的 catch 加载图像,而且我知道你只想从一个 URL

解决方案

只要先做一件事,设置一个条件,如果你的图像加载调用是在一天中第一次调用,然后捕获内存,然后在加载你的图像之后。

if(isTHisyourFirstDay){
    Glide.get(getApplicationContext()).clearMemory();
}
Glide.with(this)
    .load("https://source.unsplash.com/daily?nature")
    .into(imageView);
public static void loadImageWithGlide(Context theCtx, ImageView theImageView, String theUrl) {
        // skipMemoryCache true, because it load the same image from cache when URL not change.
        Glide.with(theCtx)
                .load(theUrl)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .skipMemoryCache(true)
                .fitCenter()
                .into(theImageView);

        // use below lines, to enable memory cache. so that image does not load again ones loaded
        //.diskCacheStrategy(DiskCacheStrategy.ALL)
        //.skipMemoryCache(false)
    }