3

Currently I have a working solution using threads (a new thread is instantiated and run for each image), but I read everywhere that threads are memory expensive and to better use other solutions in Android. But not quite sure what fits better for this case (AsynchTask, a thread pool, or ...?). The grid is scrollable, and if I scroll fast I'll be instantiating hundreds of threads at the same time...

One thing which helps is to cache the images, so the threads are just created and run the first time. But anyways, I would like to optimize this first loading.

User
  • 31,811
  • 40
  • 131
  • 232
  • 1
    Did you see this [post](http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview) ? – AMerle Jul 24 '12 at 21:14
  • Cool post, it's the same code which I'm using, with threads. – User Jul 24 '12 at 21:19

2 Answers2

2

There are a bunch of open source projects out there but doing all this stuff: loading the images asynchronously and caching them, etc. Some such projects are: https://github.com/thest1/LazyList and https://github.com/nostra13/Android-Universal-Image-Loader

LuxuryMode
  • 33,401
  • 34
  • 117
  • 188
1

I think one extra thread should be enough..I am maybe wrong, but you will have UI thread which would handle UI rendering and so on and then an AsyncTask for loading images (or thread). There you can instantiate as much parallel donwloads as possible and after each one is loaded you can send a message to the UI thread an update GridList..

Actually when you will use some other Library for HTTP connection, it would instantiate extra thread (or asynctask) for each donwload.

I have been working with this one and it works flawlessly .

simekadam
  • 7,334
  • 11
  • 56
  • 79
  • Ok, so according to this, there's nothing to optimize in my code, concerning this subject. – User Jul 24 '12 at 21:31