views:

190

answers:

1

Hey everyone!

I'm new to Android programming and I'm using AsyncTasks to fetch data in response to the user pressing a button. This works well and keeps the interface responsive while fetching the data, but when I checked out what was going on in the Eclipse debugger, I found out that every time a new AsyncTask was created (which is quite often, because they can only be used once), a new thread was being created but never terminated. The result is a large number of AsyncTask threads just sitting there. I'm not sure if this is a problem in practice or not, but I'd really like to get rid of those extra threads. How can I kill these threads?

Thanks!

+9  A: 

AsyncTask manages a thread pool, created with ThreadPoolExecutor. It will have from 5 to 128 threads. If there are more than 5 threads, those extra threads will stick around for at most 10 seconds before being removed. (note: these figures are for the presently-visible open source code and vary by Android release).

Leave the AsyncTask threads alone, please.

CommonsWare
uff! good to hear that! hehe :)
Philipz
Thanks for the explanation! I'm glad to know that I'm not doing anything wrong.Out of curiosity, why is it designed like that? Why not just end the threads after all of the methods have returned?
Computerish
Presumably to save time forking the threads on later requests.
CommonsWare