相关疑难解决方法(0)

从Glide库中的缓存中删除图像

我在我的一个项目中使用Glide来显示文件中的图像.

下面是我的代码如何显示图像:

Glide.with(DemoActivity.this)
     .load(Uri.parse("file://" + imagePath))
     .into(mImage);
Run Code Online (Sandbox Code Playgroud)

此位置(imagePath)的图像不断变化.默认情况下,滑动缓存它在中显示的图像ImageView.因此,Glide正在缓存中显示该位置新图像的第一张图像.

如果我imagePath使用具有相同名称的其他图像更改位置处的图像,则Glide将显示第一个图像而不是新图像.

两个查询是:

  1. 是否可以始终从文件中的图像而不是缓存?这样问题就解决了.

  2. 在获取新替换的图像之前,是否可以从缓存中清除图像?这也将解决问题.

android caching android-glide

55
推荐指数
13
解决办法
6万
查看次数

使用glide时删除缓存

我知道这是一个非常基本的问题。我尝试找到多种解决方案,但我无法理解它们。

我想要的是

将图像上传到服务器,作为回报,我得到了 URL,但问题是在使用此 URL 设置图像时,设置了旧图像。发生这种情况是因为滑翔正在获取旧缓存而不是更新缓存。

怎么解决这个问题。

Glide.clear(profilePic);

Glide.with(getApplicationContext())
    .load(url)
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .skipMemoryCache(true)
    .transform(new CircleTransform(MainProfile.this))
    .into(profilePic);
Run Code Online (Sandbox Code Playgroud)

目前,图片已更改,但是当我单击后退按钮并返回此活动时,它会加载旧图像。像这样从缓存加载图像。

//setting up the profile pic
Glide.with(getApplicationContext())
.load(userProfilePicUrl)
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(profilePic) {
    @Override
    protected void setResource(Bitmap resource) {
        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(MainProfile.this.getResources(), resource);
        circularBitmapDrawable.setCircular(true);

        profilePic.setImageDrawable(circularBitmapDrawable);
    }
});
Run Code Online (Sandbox Code Playgroud)

问题是,当我回到此活动时,它显示旧图片而不是新图片。

java android caching android-glide

2
推荐指数
1
解决办法
8687
查看次数

标签 统计

android ×2

android-glide ×2

caching ×2

java ×1