Glide错误IllegalArgumentException You cannot start a load for a destroyed activity

问题描述

Glide在Activity或Fragment销毁destroy时报错:

java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

解决办法

使用Glide加载图片时判断context是否为空、或使用ApplicationContext、或判断当前Activity是否被销毁

if (context !=null) {
    mGlideRequest = Glide.with(context).load(url).placeholder(R.drawable.default_img).dontAnimate().error(R.drawable.error_img);
}
Glide.with(getActivity().getApplicationContext())

原issue地址:https://github.com/bumptech/glide/issues/803
参考: https://stackoverflow.com/questions/31964737/glide-image-loading-with-application-context/32887693#32887693
参考:https://stackoverflow.com/questions/39093730/you-cannot-start-a-load-for-a-destroyed-activity-in-relativelayout-image-using-glide

上一篇 Android 5.0以下Glide加载https图片问题
下一篇 Android接入Google Play Service
目录
文章列表
1 Flutter接入Facebook和Google等三方登录
Flutter接入Facebook和Google等三方登录
2
Android布局UI优化
Android布局UI优化
3
关于Java中RSA加签解签,私钥加密公钥解密和公钥加密私钥解密代码详解
关于Java中RSA加签解签,私钥加密公钥解密和公钥加密私钥解密代码详解
4
IDEA设置SSR本地代理
IDEA设置SSR本地代理
5
React Native学习之ReactJS组件通信
React Native学习之ReactJS组件通信
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。