I am using Universal-Image-Loader to handle the display of my images, I am using a gridview like implementation in showing the images. Before the images are shown it will be downloaded first and cached into the sd card. While the images are still being downloaded, I handled the view with lazy list implementation for each images.
Problem:
After all the images are downloaded and ready for showing and every time I scroll the gridview, up and down direction the images are somewhat being downloaded again with lazy list, I believe it is being downloaded from the cache folder(sd card) of my application. Is there any way that I can keep the images(final state) while I am scrolling? Such that I don't need to downloaded it everytime I scroll to attain smooth scrolling.? I need to wait until the image is fully loaded from the sd card so that I can have smooth scrolling.
I got this setting from UIL, but I don't see any effect on this.
.resetViewBeforeLoading(false|true)
edit
I also tried this,
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));
same as below
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 10 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ImageLoaderConfiguration config =
new ImageLoaderConfiguration
.Builder(getActivity())
.threadPoolSize(3)
.memoryCache(new WeakMemoryCache())
.imageDownloader(new HttpClientImageDownloader(getActivity(), new DefaultHttpClient(manager, params)))
.build();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(icon)
.resetViewBeforeLoading(false)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
I tried experimenting, on the settings still the same.
What you should do is, you need to cache images in some directory like our application cache. Where images resides instead of memory cache. Using File caching will not increase Heap size and images will fetch from directory immediately after download.
File cacheDir = new File(this.getCacheDir(), "directory_name");
if (!cacheDir.exists())
cacheDir.mkdir();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
YourActivity.this).threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
// .memoryCache(new UsingFreqLimitedMemoryCache(2000000)) // You
// can pass your own memory cache implementation
.memoryCacheSize(1048576 * 10)
// 1MB=1048576 *declare 20 or more size if images are more than
// 200
.discCache(new UnlimitedDiscCache(cacheDir))
// You can pass your own disc cache implementation
// .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
imageLoader.clearMemoryCache();
imageLoader.clearDiscCache();
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.avatar)
.showImageForEmptyUri(R.drawable.home_shortcut).cacheInMemory()
.cacheOnDisc().build();
Note: I have used old version of UIL.
Purpose
imageLoader.clearMemoryCache();
This will clear memory when you run this code again. This is useful when your URL is same but image is different.
imageLoader.clearDiscCache();
This will clear disk before starting downloading to directory. This is useful when your directory has old images.
Memory Cache vs Disk Cache
Heap means your application memory allocation. If you don't provide disk cache, suppose your images have fix sizes of 100KB, 10 images has size of 1 MB will be stored in Memory instead of disk. While disk is not memory. It is a directory, physically on internal disk, has its own space inside. So instead of providing memory caching, disk cache is good as per memory utilization. Yes it is true that it is little bit slow but this will never effect your performance.