5/13/2014 AndroidImageLoader: Loading Images Asynchronously on Android | Wu-Man's Blog http://blog.wu-man.com/2012/10/androidimageloader-loading-images.html 1/4 31st October 2012 Almost every Android application has a need to bind remote images to a View [http://developer.android.com/reference/android/view/View.html] on screen. A very common usage is to load a bunch of remote images, cache them for later reuse, and finally bind them to each view in a scrolling AdapterView [http://developer.android.com/reference/android/widget/AdapterView.html] . Making this process efficient and memory-leak-free, however, is not exactly trivial. There are at least these performance considerations: All the IO activities need to be done in a background thread to avoid blocking the main thread. Images that fail to be loaded (usually due to network disconnection or missing resource) should be remembered so that unnecessary retrying requests are not repeated. Loading requests should be executed in a LIFO manner to improve perceived response time. Loaded images should be cached at least in memory so that future requests for the same image can be loaded faster. Asynchronously binding images to an AdapterView can be tricky. Calling BaseAdapter.notifyDataSetChanged() [http://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSe tChanged()] upon callback can be a very expensive operation. On the other hand, a major memory consideration is to avoid memory leaks. Since image loading must be done in an asynchronous manner, views holding a strong reference to Context [http://developer.android.com/reference/android/content/Context.html] inevitably have to be kept and referenced by the image loader itself. This can best be prevented by using a WeakReference [http://developer.android.com/reference/java/lang/ref/WeakReference.html] . Loaded images are to be kept in cache, which can potentially cause a memory leak if Drawable s [http://developer.android.com/reference/android/graphics/drawable/Drawable.html] are cached rather than Bitmap s [http://developer.android.com/reference/android/graphics/Bitmap.html] . To address these issues, I have forked the Image Loader [http://code.google.com/p/libs-for-android/wiki/ImageLoader] component of the libs-for- android [http://code.google.com/p/libs-for-android/] project to create the AndroidImageLoader library. AndroidImageLoader: Loading Images Asynchronously on Android
4
Embed
AndroidImageLoader_ Loading Images Asynchronously on Android _ Wu-Man's Blog
AndroidImageLoader_ Loading Images Asynchronously on Android _ Wu-Man's Blog
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
5/13/2014 AndroidImageLoader: Loading Images Asynchronously on Android | Wu-Man's Blog
Thanks for sharing this. This lib is exactly what I was looking for (using Jakewharton DiskLRUCache, Bitmap transformation, fadein, ...). I will investigate itsoon.
Reply
Chung-Ming Ts'ai 11:05 AM
Hi, I'm trying to use this library but find the dependency tree is quite deep. Is itpossible to package all the dependent libraries into an archive?
Reply
David Wu 4:31 PM
Sure I'll work on that when I have some free time next week.