Reputation: 68213
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?
Upvotes: 9
Views: 3179
Reputation: 11
https://picard.hgo.se/~jakeri03/blog/?p=39
this might be what you are looking for, uses a fixsized threadpool and a soft cache to lazyload images.
Upvotes: 1
Reputation: 43422
I tried to create a simple lazy list example that may be used as a reference, here it is Lazy load of images in ListView
Upvotes: 1
Reputation: 43544
"better" in which way? Performance wise? Developer-friendliness? Usability wise?
A couple fundamental things to consider:
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.Upvotes: 6
Reputation: 5287
The best way to have this kind of functionality is to have the images 'lazy load' in the list. If your list is of fixed size then run multiple threads (one for each visible list item), download the images and refresh the images in the list. In that mean time have some dummy image placed in the same location.
Have only a fixed number of image components for you list, preferably a few more then the total visible images at any point. Each time the list is scrolled, check whether the image corresponding to the that particular list item exists or not. If yes, display. If not, display the dummy image, run the thread to load the image in background and refresh the list image once download completes.
To further save the memory you can use 'SoftReferences' for the image components. This allows the garbage collector to take away the images that are not being shown on the screen at the moment.
Upvotes: 1