Search code examples
javaandroiduniversal-image-loader

Universal-Image-Loader does not keep the displayed images


I am handling 3mb of images and the problem is by the time I release my finger from scrolling, the images, are somewhat downloaded from the cache in my case in the sd card. I am using PauseOnScrollListener, as well and it did not solve the problem. I wanted the images to remain on the grid even if I am not viewing it, while scrolling. Universal-Image-Loader handles it differently by not showing the images while not displayed, and by the time I pause and see a particular image then that's the time it gets displayed again.

options = new DisplayImageOptions.Builder()
            .showStubImage(icon)
            //Because you reuse view for different
            //images you can see a previous image in the view while new image is loading. .resetViewBeforeLoading(true
            .showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error)
            .cacheOnDisc(true)
            .cacheInMemory(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();

Solution

  • If you are using a GridView, this is the normal behavior.

    Actually what happens is that, when you scroll through, the elements that are not visible or which are scrolled out of the screen are destroyed or in other words nullified. The reason is memory optimization and this is done by android.

    If you have any textview in your Grid Element, it will be loaded faster when it gets back into the screen. But for Images, the ImageLoader might take a little time to load the images from the cache into the ImageView. This is normal in my opinion.

    If you don't want the images to be destroyed, then you will run into OutOfMemory exception for which this is much more better.