Handler vs AsyncTask

前端 未结 8 1604
猫巷女王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:50

    If you want to do a calculation every x seconds, you should probably schedule a Runnable on a Handler (with postDelayed()) and that Runnable should start in the current UI thread. If you want to start it in another thread, use HandlerThread. AsyncTask is easier to use for us but no better than handler.

提交回复
热议问题