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.
使用步骤
1 创建一个HandlerThread,即创建了一个包含Looper的线程。
HandlerThread handlerThread = new HandlerThread("mythreadloop");
handlerThread.start();
2 获取HandlerThread的Looper
Looper looper = handlerThread.getLooper();
3 创建Handler,通过Looper初始化
Handler handler = new Handler(looper);
通过handler发送消息,就会在子线程中执行。
如果想让HandlerThread退出,则需要调用handlerThread.quit();。