The Difference between Handler and AsyncTask

| |

After we saw both Handlers and AsyncTasks a question may evolve: whats the difference between the two and when to use one of them over the other ?

The Handler is associated with the applications main thread. it handles and schedules messages and runnables sent from background threads to the app main thread.

AsyncTask provides a simple method to handle background threads in order to update the UI without blocking it by time consuming operations.

The answer is that both can be used to update the UI from background threads, the difference would be in your execution scenario. You may consider using handler it you want to post delayed messages or send messages to the <strong>MessageQueue</strong> in a specific order.

You may consider using AsyncTask if you want to exchange parameters (thus updating UI) between the app main thread and background thread in an easy convinient way.

Related Posts by Categories

0 comments:

Post a Comment