开发者

Understanding AsyncTask

开发者 https://www.devze.com 2023-04-06 17:27 出处:网络
Once an AsyncTask call开发者_如何学运维 is finished is the thread deleted? I stored an AsyncTask in a var \"guiThread = (GUIAsyncTask) new GUIAsyncTask()\".

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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消