解决方案:
在使用Glide的地方加上这个判断;Util是系统自带的;
if(Util.isOnMainThread()) {
Glide.with(AppUtil.getContext()).load(R.mipmap.iclunch).error(R.mipmap.cuowu).into(imageView);
}
在使用的Glide的界面的生命周期onDestroy中添加如下代码:
@Override
protected void onDestroy() {
super.onDestroy();
if(Util.isOnMainThread()) {
Glide.with(this).pauseRequests();
}
}
上面Destroy中with(this),改成with(AppUtil.getContext());
不然会报: java.lang.IllegalStateException: Activity has been destroyed
扩展:
Glide.with(AppUtil.getContext()).resumeRequests()和 Glide.with(AppUtil.getContext()).pauseRequests()的区别:
1.当列表在滑动的时候,调用pauseRequests()取消请求;
2.滑动停止时,调用resumeRequests()恢复请求;
另外Glide.clear():当你想清除掉所有的图片加载请求时,这个方法可以用到。
ListPreloader:如果你想让列表预加载的话,可以试试这个类。
请记住一句话:不要再非主线程里面使用Glide加载图片,如果真的使用了,请把context参数换成getApplicationContext;
推荐一个使用Glide参考博客:http://blog.csdn.net/zhihui_520/article/details/51822336