Why use HandlerThread in Android

前端 未结 6 1619
名媛妹妹
名媛妹妹 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:44

    As Doc says :

    Handy class for starting a new thread that has a looper.
    The looper can then be used to create handler classes.
    Note that start() must still be called.

    HanderThread class inherits from the Thread class, which encapsulates the Looper object, so that we do not care The Looper open and release details. Like in case of normal thread we need to use Looper.prepare() and Looper.loop() to convert it as a LooperThread.

提交回复
热议问题