I have custom ListFragment
with custom ListAdapter
and four navigation tabs with another content . I need to display some images that need to be downloaded from URLs in that Fragment
.
I've tried to use Universal Image Loader. It works fine, but it seems that it doesn't cashe my files, although I have it set to. Every time I open another tab and then get back to this one images starting to download again.
I'm calling displayImage(String url, ImageView view, DisplayImageOptions options)
from getView()
of ListAdapter
.
Question:
How can I make UIL not to download images every time the Activitiy
or Fragment
is recreated?
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.blue_background)
.cacheInMemory()
.cacheOnDisc()
.build();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
Are you sure that it downloads images another time. that shouldn't happen unless you have specified a small size of disk cache or because it saves your images only in memory it deletes old images when the max size you specified for the memory is reached!! Try to not use the inMemory cache and only disk cache and try to specify more time for loading images the default value for this is 1000ms :
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_empty)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_empty)
.resetViewBeforeLoading()
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT) // default
.bitmapConfig(Bitmap.Config.RGB_565) // default
.displayer(new SimpleBitmapDisplayer()) // default
.handler(new Handler()) // default
.build();