I’ve got a listview with the list of some user’s facebook friends, with each row showing the name and the picture of the friend. To get the picture from Facebook I launch a thread using ASyncTask, following Gilles Debunne’s post “Multithreading For Performance”.
When I scroll down the list until the end, the number of threads launched can be huge, which makes everything very slow until all threads finish their task.
How can I limit the number of threads?
Thanks
Julien
Right now, unless you are willing to limit yourself to API Level 11 (Android 3.0) and higher, you cannot limit the number of threads used by
AsyncTask. IIRC, it will use up to 20 threads maximum.If you want fewer than that, you will need to create your own thread pool mechanism and use that instead of
AsyncTask. Or, clone the code fromAsyncTaskinto your own project and modify the characteristics of its own thread pool.