要创建新的异步任务为每个不同的呼叫或使用同一个 [英] should you create new Async Tasks for every different call or use the same one
本文介绍了要创建新的异步任务为每个不同的呼叫或使用同一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我有一个应用程序,这将使多发性HTTP发布/获取
So I have an app that will make multipe HTTP Post/Gets
例如。登录,getThisData,getThatData,sendThis,sendThat
E.G. Login, getThisData, getThatData, sendThis, sendThat
是不是最好有一个单独的AsyncTask来处理每一个
Is it better to have a seperate AsyncTask to handle each one
或者人们异步任务,并用不同的交换机处理它们在 onPostExecute
和 doInBackground
Or one async task and process them differently with a switch in onPostExecute
and doInBackground
干杯
推荐答案
简短的回答是肯定的,你应该创建新的AsncTask 每次调用。
Short answer is yes you should create a new AsncTask for each call.
如果你感兴趣的话,从长远的回答是;
And if you interested, the long answer is;
- 中的AsyncTask的目标是照顾的线程管理的为你和你不应该担心线程机制。
- 的Android平台处理线程池来管理异步操作。 AsyncTasks就像是消耗品。该任务可以只执行一次(如果是第二次执行尝试一个异常将被抛出。)
快乐异步编码! : - )
Happy asynchronous coding! :-)
这篇关于要创建新的异步任务为每个不同的呼叫或使用同一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文