Search This Blog

Wednesday, 10 October 2012

Android : Lazy loading and Caching of Images with Image downloader

Downloading does always fascinated me. When we download movie, song or Wallpaper. But when i went into development then i came to know how much complication involve in that.
I saw so many people struggling in downloading. So i decide to make one download manager for all android developer. And now i am revealing all my hard work to you guys so that it make your work much easier.

When to use AhamdDownloaderManager :->

   when you want to download images
  •  When you want to cache images for later use
  • When you want to handle network failure and other error.

When not to use AhamdDownloaderManager :->

If you want to download Video, Mp3 then its not for you guys

Qualities of AhamdDownloaderManager :->

  • It will check automatically your sdcard is mounted or not and give you alert
  • Return a callback with Bitmap value as null if in any case Image is not successfully downloaded
  • Save all image inside sdcard and later on it use these image if URL name is same.
  •  Fast

How to use AhamdDownloaderManager :->

Step 1) Download Jar and add to your project. Download this Jar and to your project
Step 2) It handle progress untill your images downloaded so create your layout similar like this

<RelativeLayout xmlns:android=""
    android:layout_height="fill_parent" >

        android:scaleType="fitXY" >

        android:visibility="visible" />


Step 3) Now set AhamdDownloaderManager to load images

  ImageView img = (ImageView) findViewById(;
  ProgressBar bar = (ProgressBar) findViewById(;
  AhmadDownloadManager ahmadDownload = new AhmadDownloadManager(this);
  ahmadDownload.DisplayImage(Url_To_download, this, img, bar, this);

Step 4) Handle failure : - We have one call back interface that we have to implement in Step 3

 public void result(Bitmap bitmap) {
  Log.i("AhmadDownloadCallback", "Not able to download");


Update 1.0.1 : I updated it on demand of my reader for reason likes.

1) How to scale image on base of custom height and width : New download jar have method 

ahmad.setCustomHeight(100, 100);


2) Avoiding condition if your URL is null : set Custom URL in new jar


Download Sample Project

Android News and source code