Handler vs AsyncTask

前端 未结 8 1634
猫巷女王i
猫巷女王i 2020-11-28 18:36

I\'m confused as to when one would choose AsyncTask over a Handler. Say I have some code I want to run every n seconds which will update the UI. Why would I choose one ove

8条回答
  •  青春惊慌失措
    2020-11-28 18:38

    They are best interview question which is asked. AsyncTask - They are used to offload of UI thread and do tasks in background. Handlers - Android dosent have direct way of communication between UI and background thread. Handlers must be used to send message or runnable through the message queue.

    So AsyncTasks are used where tasks are needed to be executed in background and Handlers are used for communication between a UI and Background Thread.

提交回复
热议问题