我的服务类中有以下带有构造函数的线程。
public class communicationDetails extends Thread {
communicationDetails(final Handler _handler, final Handler conn_handler) throws IOException {
mhandler = _handler;
connHandler = conn_handler;
}
在我的服务的onCreate
中,我试图构造线程并启动它。第一个处理程序工作正常,我能够发送消息。由于我想延迟发布消息,因此在第二个处理程序中,我尝试使用postDelay方法。这就是问题所在。
try {
communication_Details = new communicationDetails(
// works fine
new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(final Message msg) {
// sending messages
}
},
//this throws an error
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
// call a method
}
}, 2000));
} catch (IOException e) {
e.printStackTrace();
}
communication_Details.start();
我收到以下错误。我在这里犯了什么愚蠢的错误?还是完全错误的方法。
error: incompatible types: boolean cannot be converted to Handler