I read several topics on lazy loading a list in stackoverflow, and I'm trying to figure out how to work with different cache levels in android.
As mentioned here:
Lazy loading images in a ListView
I used
Multithreading for performance , by Gill Debunn.
Example. I modified it to just work in the correct way, and also work with 1.6. Here is the code:
public class ImageDownloader { private static final String TAG = "ImageDownloader"; private static final int HARD_CACHE_CAPACITY = 40; private static final int DELAY_BEFORE_PURGE = 10 * 1000;
}
I fully understand the logic of this example, however I am confused why this is not working properly.
We have two cache levels: hard cache and SoftReference cache. We save the bitmap images in the hard cache, and then when it is full we save in SoftReference and reorder the hard cache.
Then I close the application, close the Internet and restart it. In the constructor, we call resetPurgeTimer (), which clears the cache and therefore nothing is in the cache. To avoid this, I commented on this line so as not to clear the cache. I am restarting my application and I can see 6-7 images that are present in the SoftReference cache (according to LogCat).
I know that the SoftReference cache may be empty when the GC is called, but it is almost empty even before the application is closed or Wi-Fi is turned off ... There is a known error with SoftReferences that are garbage collected even without memory loss.
Is there something wrong with this widely used example?
Thanks in advance,
Andreas
source share