Skip to content Skip to sidebar Skip to footer

Correct Usage Of Universal Image Loader

Ok, I've been trying to optimize my photo gallery for days now (this is my first Android project). All photos are loaded via Web page. I've started using Universal Image Loader, bu

Solution 1:

You should consider using asynctask to get urls from the server.

You use should be using a view holder for smooth scrolling and performance. http://www.youtube.com/watch?v=wDBM6wVEO70. The talk is about view holder and listview performance.

http://developer.android.com/training/improving-layouts/smooth-scrolling.html

https://github.com/nostra13/Android-Universal-Image-Loader. Check the topic under Configuration and Display Options.

Instead of downloading it again you should cache images in phone memory or sdcard.

It caches images in say sdcard (if you have configured properly) using url as the key. If present display from cache else download, cache and display images.

In your custom adapter constructor

FilecacheDir= StorageUtils.getOwnCacheDirectory(activity context, "your folder");//for caching// Get singletone instance of ImageLoader
 imageLoader = ImageLoader.getInstance();
 // Create configuration for ImageLoader (all options are optional)ImageLoaderConfigurationconfig=newImageLoaderConfiguration.Builder(a)
 // You can pass your own memory cache implementation
.discCache(newUnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(newHashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = newDisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.showImageOnLoading(R.drawable.default_pic)//display stub image until image is loaded
.displayer(newRoundedBitmapDisplayer(20))
.build();

In your getView()

viewholder.image=(ImageView)vi.findViewById(R.id.imageview); 
imageLoader.displayImage(imageurl, viewholder.image,options);//provide imageurl, imageview and options.

Post a Comment for "Correct Usage Of Universal Image Loader"