There are a couple ways of getting data Asynchronously in your app. One is a Handler and another one is an AsyncTask. Now I’ve used both, and would like to know which one performs better/more efficiently at some tasks.
Thusfar, I’ve mostly used AsyncTasks in getting Webdata, and Handler‘s in getting data from Services to Activities.
I would like to know if there is an advantage to using Handler‘s for Webdata, or using AsyncTasks for refreshing UI from Services. What is the big difference?
Since
AsyncTaskuses aHandler, your comparison is… odd.AsyncTaskis great for transactional work: stuff that will take more than a few milliseconds and less than a few minutes. For that sort of work, if you have no need for your own thread management,AsyncTaskis generally simpler to use.If you have some particular characteristics that you need for your threading that
AsyncTaskwill not readily handle, or if you need the thread for an indeterminate period of time (e.g., until the user presses a Stop button), use your own thread and something else to get work to the main application thread: aHandler, orpost(), orrunOnUiThread(). The “indeterminate period of time” recommendation assumes you are using one of the built-in thread pools — I am never a fan of tying up a thread out of a thread pool that you didn’t set up.