1

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?

Arzozeus
  • 103
  • 2
  • 11

1 Answers1

0

Make sure when get image from url allow Cache option :

boolean memCache = false;
boolean fileCache = true;

aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png", memCache, fileCache);

Ref : http://code.google.com/p/android-query/wiki/ImageLoading

Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • Thanks for your fast reply, I have include both boolean (memCache = false; boolean fileCache = true;) on the begging of the function, but the first time run it the second image will return null and the second time i run it and it is able to cache the url. – Arzozeus Nov 28 '14 at 05:42
  • @Arzozeus,might be when you go first time second image will not be downloaded to cache area due to slow connection or larger image. – Haresh Chhelana Nov 28 '14 at 05:46
  • those image just few kb size, I think not the problem of image size or slow connection. Just dont know why the second time both can get cache, and the first time second image return null – Arzozeus Nov 28 '14 at 05:54
  • @Arzozeus,i think something going wrong in are code becz AndroidQuery work perfectly for image loading. – Haresh Chhelana Nov 28 '14 at 05:57
  • Haresh Chhelana,might be. Just the same code I run twice, and the first time run it second image unable to cache, close the page and run again and able to cache for both image. Just curious isn't getCachedImage only able to cache one url at a time in the same function? – Arzozeus Nov 28 '14 at 06:02
  • @Arzozeus,getCachedImage is use to get the bitmap for a previously fetched image from given url. – Haresh Chhelana Nov 28 '14 at 06:06
  • Haresh Chhelana, thanks for your help, I will check again my code, isn't anything I did wrong. – Arzozeus Nov 28 '14 at 06:11