如果我们看到下一件事,我在代码中看到了很多示例:
HandlerThread thread = new HandlerThread("Thread1");
thread.start();
mLoadHandler = new Handler(thread.getLooper())
mLoadHandler.post(new Runnable() {
public void run() {
// run some code
//methodA();
}
});
您还可以在以下位置找到它:
为什么他们HandlerThread只为一个目的创建一个:将它传递Looper给一个新的Handler. 为什么不只是扩展HandlerThread并在那里执行所有代码(methodA())?或者创建一个 Handler 实例并在那里调用:
Looper.prepare();
Looper.loop();