当前位置:网站首页>图片更新之后Glide加载依旧是原来的图片问题
图片更新之后Glide加载依旧是原来的图片问题
2022-08-01 05:05:00 【才疏学浅,努力修炼】
原因
Glide加载相同URL时由于缓存无法更新图片
解决方法
1,去掉缓存
如果是本地图片,可以采取取消缓存的方式,这样是比较简单的操作:
.skipMemoryCache(true) // 不使用内存缓存
.diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
.into(imageView);
2,使用signature
无论本地图片网络图片,都可以使用另一个方法,就是使用Glide的方法.signature(Key signature),通过创建一个签名,然后在图片更新的时候,更改签名,达到重新加载的效果。该签名可以是个String,可以是图片更新的时间
Glide.with(getActivity())
.load(urlString)
.signature(new ObjectKey(DateTimeUtil.GetNowTime()))//也可以利用系统毫秒System.currentTimeMillis()
.into(portrait);
注意:Glide 4.0中new StringSignature()类已经不在被支持,需改为new ObjectKey()
使用的工具类
public class DateTimeUtil {
public static String GetNowTime() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
String str = formatter.format(curDate);
return str;
}
}
边栏推荐
- typescript27-枚举类型呢
- typescript26-字面量类型
- (2022牛客多校四)N-Particle Arts(思维)
- 罗技鼠标体验记录
- API Design Notes: The pimpl trick
- typescript24 - type inference
- pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
- Swastika line-by-line parsing and realization of the Transformer, and German translation practice (2)
- pytorch、tensorflow对比学习—张量
- 状态压缩dp
猜你喜欢
剑指 Offer 68 - II. 二叉树的最近公共祖先
PAT serie b write the number 1002
冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
万字逐行解析与实现Transformer,并进行德译英实战(一)
typescript27 - what about enumeration types
UE4 模型OnClick事件不生效的两种原因
pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
typescript21 - Comparison of Interfaces and Type Aliases
typescript23-元组
typescript24 - type inference
随机推荐
C# | 使用Json序列化对象时忽略只读的属性
MySQL-数据定义语言-DDLdatebase define language
I met a shell script
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
基于Arduino制作非接触式测温仪
Excel做题记录——整数规划优化模型
(2022牛客多校四)A-Task Computing (排序+动态规划)
【堆】小红的数组
剑指 Offer 68 - II. 二叉树的最近公共祖先
高数 | 【重积分】线面积分880例题
pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
Selenium:操作Cookie
万字逐行解析与实现Transformer,并进行德译英实战(一)
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
【目标检测】YOLOv7理论简介+实践测试
typescript22-接口继承
PMP子过程定义总结
MySQL Practice Summary -
PAT乙级 1002 写出这个数
(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)