kjs3
kjs3

Reputation: 6178

Understanding AsyncTask

Once an AsyncTask call is finished is the thread deleted?

I stored an AsyncTask in a var "guiThread = (GUIAsyncTask) new GUIAsyncTask()". The first call to execute() works but subsequent calls don't. So, do I just create new tasks whenever I need them? I was under the impression that I used my variable over and over and calling new over and over would spin up thousands/millions of threads.

Upvotes: 1

Views: 305

Answers (3)

Enoobong
Enoobong

Reputation: 1734

An AsyncTask must be created any time it is to be used

Upvotes: 0

PravinCG
PravinCG

Reputation: 7708

Nope you need to create a new AyncTask everytime you want to use it.

Upvotes: 1

DeeV
DeeV

Reputation: 36035

AsyncTasks are one-time uses. They start, execute, then die. Then you have a choice of keeping the reference around to gather information from it that may be stored in the class post-execute, or dumping the reference and letting the garbage collector handle it. If you want to start the AsyncTask again, you have to create a new object and start it.

Upvotes: 3

Related Questions