HandlerThread

HandlerThread:

要使用Looper才能建立Android的消息机制,Thread的确是可以自己通过代码来实现HandlerThread的功能,但你看HandlerThread的API介绍: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.可以说它本身就是个简化需要实现消息机制的Thread类代码的类,帮你把一些必要的代码都已经写好了。另外重写它的onLooperPrepared方法可以帮你做一些Looper开始loop之前的初始化工作,代码更加清晰

handler与activity在同一个线程中,handlerthread与activity不在同一个线程,而是别外新的线程中


你可能感兴趣的:(HandlerThread)