Hi, I'm about to create a lazy image loader for images both from device and from the web for a ListView. I'm thinking of what to use and how, on one hand i can use a thread that pools my request (always running, and i can attach a view and an adapter and it will handle the image loading for me), cache my allready loaded images and checks for the visibility of the images before i load so i wont do unneeded job.
I had another thought of using the AsyncTask like many suggest in the forum. Terhe is one drawback though.I see that many use new MyTask().execute(urls);
this presents a problem if i want to start loading and stop loading images on demand.
If i use the async task per image then i need new async task for each image, that's a lot of 'new' to make, i can use a pool, but if too many async tasks are stuck, i will still create about 150-200 asyc tasks, too many for my taste...
What do you guys think ? i think a thread will do a nicer job here: 1. keep on running till killed 2. try to get a job from the queue, if not jobs, wait. 3. if a job is available, get it and start processing. 4. each request is processed alone,serially and blocks the thread. 5. once does goes on with '2'. 6. each enqueue that is done by the adapter using startLoadingImage() for views that need to be displayed will create anew job and call notify on the wait lock. I can optimize this code with a pool of threads if i want several GET\POST requests in parallel. Also I'm caching the images i already downloaded \ loaded for fast load on next access. the idea is to minimize GC and list's slagging.