Why use HandlerThread in Android

前端 未结 6 1611
名媛妹妹
名媛妹妹 2020-12-14 09:43

In android , Handler can be used to post / handle message, if I don\'t use a HandlerThread (pass its Looper to Handler), does that mean in this case Handler use MainThread (

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 10:39

    HandlerThread is useful when you want to execute a lot of background tasks, since it has its own looper. Normally if you post a message to a Handler it uses the MainThread's looper. This means that that the task is executed on the UI Thread. But in the case of HandlerThread, these tasks are executed on the worker thread. You can find a more detailed explanation here

提交回复
热议问题