Activity中 Glide加载image的时候,activity关闭,报错问题处理
程序员文章站
2022-05-28 22:41:48
...
public static boolean isDestory(Activity activity){ if(activity==null){ return true; } else if(activity.isFinishing()){ return true; } else if(activity.isDestroyed()){ return true; } else{ return false; } }
public static void loadImage(Context context, int uri, ImageView imageView) { if(Utils.isNotEmpty(uri)){ RequestOptions options = new RequestOptions() .centerCrop() .placeholder(placeholderSoWhite) .error(errorSoWhite) .diskCacheStrategy(DiskCacheStrategy.ALL); Glide.with(context).load(uri).apply(options).into(imageView); } }
if (!isDestory((Activity) mContext)) { loadImage((Activity) mContext, R.mipmap.ic_launcher, mAvatar); }