glide activity has been destroyed (Glide V4)

使用glide加载图片是对Ccontext检查是否可用,

 

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)

public static boolean canLoad(Context context){

if(context == null){

return false;

}

if(context instanceof Activity){

return !((Activity) context).isDestroyed();

}

return true;

}

补充:仍然会异常:

@TargetApi() 只屏蔽某一新api中才能使用的方法报的android lint错误

 

修正方案:sdk>=17 调用activity.isDestroyed();

public static boolean canLoad(Context context){

if(context == null){

return false;

}

if(context instanceof Activity && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){

return !((Activity) context).isDestroyed();

}

return true;

}

 

 

 

 

 

你可能感兴趣的:(android)