I am a little confused on ThreadPoolExecutor. Here is what I am trying to accomplish:
I have a list-view which is populated with an image icon to the left and a short description to its right. I have all of the text already defined statically, however i want to get the icons from the the web. I already know how to get the image from a url, however I dont want to spawn 'n' amount of threads per icon to grab the icon image. So i read up on threadpoolexecutor for asynctask and I am not sure how to go about it. can you guys give me a head start? do I have to create a threadpoolexecutor and use asynctasks within it?
My list is like this.. without the icons.
___________________________
[icon][a short description]
____________________________
[icon][a short description]
_____________________________
[icon][a short description]
_____________________________
[icon][a short description]
____________________________
I would recommend just using AsyncTask and not worry about the ThreadPoolExecutor
, which requires HoneyComb anyway. AsyncTask has a pool of threads that will be reused for all of your list items. It won't create a bunch of threads per icon.
Just keep in mind that your tasks will be running in parallel on Android 2.x and to keep track of any synchronization issues your code might have.
You will need to use method executeOnExecutor() to start it with your own executor.
There seems to be number of gotchas, so read carefully the entire page for AsyncTask
.
So yes, you can create your own ThreadPoolExecutor
and use it with AsyncTask
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With