我正在使用一个查询getCachedImage来缓存来自我的服务器的图像url,但我面临一些问题。如果我在同一个函数中运行两次,第一次缓存成功,但第二次将返回null。当我关闭该页面并再次运行,并且两者都成功时,我希望确保每次运行时,它们都可以缓存图像,以下是我的代码
boolean memCache = false;
boolean fileCache = true;
Bitmap dealimage = null;
Bitmap dealimage2 = null;
String dealImg = null;
String dealImg2 = null;
try {
JSONArray jsonarray = new JSONArray(imgStr);
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jobj = jsonarray.getJSONObject(i);
dealImg = jobj.getString("IMG1").toString();
dealimage = aq.getCachedImage(dealImg);
System.out.println("Image : " + dealimage);
dealImg2 = jobj.getString("IMG12").toString();
dealimage2 = aq.getCachedImage(dealImg2);
System.out.println(" Second Image : " + dealimage2);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}结果LogCat
(第一次)图像: android.graphics.Bitmap@438e79d8小图像:空
(第二次)图片: android.graphics.Bitmap@42665560小图片: android.graphics.Bitmap@42891098
我希望两个结果都可以在第一次缓存,而不是第二次。为什么第一次不能缓存第二个镜像?但是第二次两者都能缓存它吗?有人能帮上忙吗?
发布于 2014-11-28 13:35:59
确保从url获取图像时允许缓存选项:
boolean memCache = false;
boolean fileCache = true;
aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png", memCache, fileCache);参考:http://code.google.com/p/android-query/wiki/ImageLoading
https://stackoverflow.com/questions/27182482
复制相似问题