Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better loading of images for ListView?

Tags:

android

I am wondering if which of the two is better in loading images in a listview from web, is it by batch through some number of threads that are running simultaneously or one by one through thread queue?

I have noticed (but I don't know if that is really the implementation) from the youtube app that the images are loaded by batch and it is kinda fast. Even for not only loading images but also requesting some data from the web as well. Does anyone have an idea?

like image 968
capecrawler Avatar asked Jan 19 '10 08:01

capecrawler


1 Answers

"better" in which way? Performance wise? Developer-friendliness? Usability wise?

A couple fundamental things to consider:

  1. Creating threads is expensive. It's slow and each thread consumes system resources (of course). When creating a single thread for each download, use a managed capped thread pool.
  2. Don't load images if they're not visible to the user. What you should do is in getView() of your ListAdapter, check whether the image has already been loaded, and if not, re-use a thread from the thread pool to do the work.
  3. Be careful with AsyncTask. As far as I know, AsyncTask manages a fixed, application wide thread pool (I think it's capped to 5 threads), so if all these threads are busy loading images, any other task you perform through that class will block.
  4. Don't re-invent the wheel. Does the ImageLoader of Droid-Fu solve your problem? It also implements a cache, so images aren't downloaded twice.
like image 168
Matthias Avatar answered Sep 27 '22 17:09

Matthias