Blog

Lazy loading images libraries for android

Almost every android app has a need to load remote images. While loading remote images, we have to take care of below things:

Image loading process must be done in background (i.e. asynchronously) to avoid blocking UI main thread.

Image recycling image should be done.

Image should be displayed once its loaded successfully.

Images should be cached in local memory for the later use.

If remote image gets failed (due to network connection or bad url or any other reasons) to load then it should be managed perfectly for avoiding duplicate requests to load the same again, instead it should load if and only if net connection is available.

Memory management should be done efficiently.

In short, we have to write a code to manage each and every aspects of image loading but there are some awesome libraries available, using which we can load/download image asynchronously. We just have to call the load image method and success/failure callbacks.

1. Universal Image loader

Universal Image loader aims to provide a powerful, flexible and highly customizable instrument for image loading, caching and displaying. It provides a lot of configuration options and good control over the image loading and caching process.

For development you can enable the display of a colored ribbon which indicates the image source

3. Fresco

Displaying images quickly and efficiently on Facebook for Android is important. Yet we have had many problems storing images effectively over the years. Images are large, but devices are small. Each pixel takes up 4 bytes of data — one for each of red, green, blue, and alpha. If a phone has a screen size of 480 x 800 pixels, a single full-screen image will take up 1.5 MB of memory. Phones often have very little memory, and Android devices divide up what memory they have among multiple apps.

4. ION

It is a popular Android Asynchronous Networking and Image Loading. The ion provide following features.

Asynchronously download:

Images into ImageViews or Bitmaps (animated GIFs supported too)

JSON (via Gson)

Strings

Files

Java types using Gson

Easy to use Fluent API designed for Android

Automatically cancels operations when the calling Activity finishes

Manages invocation back onto the UI thread

All operations return a Future and can be cancelled

HTTP POST/PUT:

text/plain

application/json - both JsonObject and POJO

application/x-www-form-urlencoded

multipart/form-data

Transparent usage of HTTP features and optimizations:

SPDY and HTTP/2

Caching

Gzip/Deflate Compression

Connection pooling/reuse via HTTP Connection: keep-alive

Uses the best/stablest connection from a server if it has multiple IP addresses

Cookies

View received headers

Grouping and cancellation of requests

Download progress callbacks

Supports file:/, http(s):/, and content:/ URIs

Request level logging and profiling

Support for proxy servers like Charles Proxy to do request analysis

Based on NIO and AndroidAsync

Ability to use self signed SSL certificates

5. Novoda image-loader

image-loader is a simple library that makes it easy to download, display and cache remote images in Android apps. Image download happens off the UI thread and the images are cached with a two-level in-memory/SD card cache

So now I am sure now you can be able to compare libraries. Choosing library is a bit difficult talk because it always depends on the requirement and type of projects.