Android universal image loader



Multithread image loading
Chance of wide tuning ImageLoader’s configuration (thread pool size, HTTP options, memory and disc cache, display image options, yet others)
Chance of image caching in memory and/or on device’s file sysytem (or Sdcard)
Possible ways to “listen” loading process
Possible ways to personalize every display image call with separated options
Widget support

Android 1.5+ support


Universal Image Loader. Part 1 – Introduction [RU EN]
Universal Image Loader. Part 2 – Configuration [RU EN]
Universal Image Loader. Part 3 – Usage [RU EN]

(*) a little outdated
User Support

Start looking at Helpful Info.

For those who have some question or problems (including OOM) about Universal Image Loader you are able to request it on StackOverFlow with [universal-image-loader] tag. Include [java] and [android] tags. Mention next information inside your question/problem:

your configuration (ImageLoaderConfiguration)
display options (DisplayImageOptions)
getView() method code of the adapter (if you are using it)
XML layout of the ImageView you load image into

Bugs and have demands place here.

ImageView imageView = …
String imageUrl = “” // or “file:///mnt/sdcard/images/”

// Get singletone demonstration of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance()
// Initialize ImageLoader with configuration. Get it done once.
// Load and display image asynchronously
imageLoader.displayImage(imageUrl, imageView)

Most detailed

ImageView imageView = …
String imageUrl = “” // or “file:///mnt/sdcard/images/”
ProgressBar spinner = …
File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), “UniversalImageLoader/Cache”)

// Get singletone demonstration of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance()
// Create configuration for ImageLoader (all choices are optional, only use individuals you want to personalize)
// DON’T COPY THIS CODE For Your PROJECT! Case illustration of using ALL options. Many of them have default values.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.memoryCacheExtraOptions(480, 800) // max width, max height
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75) // Can slow ImageLoader, utilize it carefully (Better avoid using it)
.threadPriority(Thread.NORM_PRIORITY – 1)
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You are able to pass your personal memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You are able to pass your personal disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.imageDownloader(new URLConnectionImageDownloader(5 * 1000, 20 * 1000)) // connectTimeout (5 s), readTimeout (20 s)
// Initialize ImageLoader with produced configuration. Get it done once on Application start.

// Produces display image choices for custom display task (all choices are optional)
DisplayImageOptions options = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer(20))
// Load and display image
imageLoader.displayImage(imageUrl, imageView, options, new ImageLoadingListener()
public void onLoadingFailed(FailReason failReason)
public void onLoadingComplete(Bitmap loadedImage)
public void onLoadingCancelled() Do nothing at all


// Just load image
DisplayImageOptions options = new DisplayImageOptions.Builder()
.displayer(new FakeBitmapDisplayer())
ImageSize minImageSize = new ImageSize(120, 80)
imageLoader.loadImage(context, imageUrl, minImageSize, options, new SimpleImageLoadingListener() anything you want with loaded Bitmap


Helpful info

Caching isn’t enabled automatically. If you would like loaded images is going to be cached in memory and/or on disc then you need to enable caching in DisplayImageOptions by doing this:

// Create default options which is employed for every
// displayImage(…) call if no options is going to be passed for this method
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()


ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())


ImageLoader.getInstance().init(config) // Get it done on Application start

// Then later, when you wish to show image
ImageLoader.getInstance().displayImage(imageUrl, imageView) // Default options is going to be used

or by doing this:

DisplayImageOptions options = new DisplayImageOptions.Builder()


ImageLoader.getInstance().displayImage(imageUrl, imageView, options) // Incoming options is going to be used

Should you enabled disc caching then UIL attempt to cache images on exterior storage (/sdcard/Android/data/[package_title]/cache). If exterior storage isn’t available then images are cached on device’s filesytem. To supply caching on exterior storage (Sdcard) add following permission to AndroidManifest.xml:

How UIL define Bitmap size required for exact ImageView? It searches defined parameters:
Get android:layout_width and android:layout_height parameters
Get android:maxWidth and/or android:maxHeight parameters
Get maximum width and/or height parameters from configuration (memoryCacheExtraOptions(int, int) option)
Get width and/or height of device screen

So attempt to set android:layout_widthandroid:layout_height or android:maxWidthandroid:maxHeight parameters for ImageView knowing approximate maximum size it. It can help properly compute Bitmap size required for this view and save memory.

Should you frequently got OutOfMemoryError inside your application using Universal Image Loader then try set WeakMemoryCache into configuration:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())

.memoryCache(new WeakMemoryCache())


or disable caching in memory whatsoever (in DisplayImageOptions).

For memory cache configuration (ImageLoaderConfiguration.Builder.memoryCache(…)) you should use ready to eat implementations:
UsingFreqLimitedMemoryCache (Minimal commonly used bitmap is erased when cache size limit is exceeded) – Used automatically
LRULimitedMemoryCache (Least lately used bitmap is erased when cache size limit is exceeded)
FIFOLimitedMemoryCache (FIFO rule can be used for deletion when cache size limit is exceeded)
LargestLimitedMemoryCache (The biggest bitmap is erased when cache size limit is exceeded)
LimitedAgeMemoryCache (Decorator. Cached object is erased when wear and tear surpasses defined value)
WeakMemoryCache (Memory cache with only weak references to bitmaps)

For disc cache configuration (ImageLoaderConfiguration.Builder.discCache(…)) you should use ready to eat implementations:
UnlimitedDiscCache (The quickest cache, does not limit cache size) – Used automatically
TotalSizeLimitedDiscCache (Cache restricted to total cache size. If cache size surpasses specified limit then file most abundant in earliest last usage date is going to be erased)
FileCountLimitedDiscCache (Cache restricted to file count. If file count in cache directory surpasses specified limit then file most abundant in earliest last usage date is going to be erased. Utilize it in case your cached files are of comparable size.)
LimitedAgeDiscCache (Size-limitless cache with limited files’ lifetime. If chronilogical age of cached file surpasses defined limit then it will likely be erased from cache.)

NOTE: UnlimitedDiscCache is 30%-faster than other limited disc cache implementations.

To show bitmap (DisplayImageOptions.Builder.displayer(…)) you should use ready to eat implementations:
RoundedBitmapDisplayer (Shows bitmap with rounded corners)
FadeInBitmapDisplayer (Shows image with “fade in” animation)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>