I am using Aquery getCachedImage to cache the image url from my server, but I am facing some problem. If I run it twice in a same function and the first cache is successful but the second will return null. When I close that page and run again and both successful, I want to make sure every time I run, both of it can cache the image, below is my code
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());
}
Result LogCat
(First time) Image : android.graphics.Bitmap@438e79d8 Small Image : null
(Second time) Image : android.graphics.Bitmap@42665560 Small Image : android.graphics.Bitmap@42891098
I want both the result can cache in the first time instead of the second time. Why the first time the second image cannot be cache? But the second time both of it able to cache it? Can anyone help?
Make sure when get image from url allow Cache option :
Ref : http://code.google.com/p/android-query/wiki/ImageLoading