should you create new Async Tasks for every different call or use the same one

前端 未结 4 820
[愿得一人]
[愿得一人] 2020-12-18 12:44

So I have an app that will make multipe HTTP Post/Gets

E.G. Login, getThisData, getThatData, sendThis, sendThat

Is it better to have a seperate AsyncTask to

4条回答
  •  囚心锁ツ
    2020-12-18 13:11

    Short answer is yes you should create a new AsncTask for each call.

    And if you interested, the long answer is;

    According to the Android's Asynctask documentation,

    • The goal of the AsyncTask is to take care of thread management for you and you should not worry about the threading mechanisms.
    • The Android Platform handles the pool of threads to manage the asynchronous operations. AsyncTasks are like consumables. The task can be executed only once (an exception will be thrown if a second execution is attempted.)

    Happy asynchronous coding! :-)

提交回复
热议问题