我需要开发异步网络通信,我对如何做到这一点感到有些困惑。
我有Runnable
:
private Runnable runnableFirmwareUpdate = new Runnable() {
@Override
public void run() {
byte[] bufferIsAlive = getIsAliveBuffer();
UDPService.stopService();
firmwareHandler = FirmwareHandler.getInstance();
firmwareHandler.startFeedback();
try {
Thread.sleep(200);
} catch (InterruptedException ignored) {
}
firmwareHandler.UDPSend(bufferIsAlive);
//I want to pause process here and continue after the feedback method bellow
((Activity)view.getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(view.getContext(),"Continuou", Toast.LENGTH_SHORT).show();
}
});
}
};
我有这个方法:
public static void feedbackMessage(byte[] buffer){
//Here I'll receive the UDP answer as well...
}
我的问题是:"我怎样才能"暂停" firmwareHandler.UDPSend(bufferIsAlive);
之后的过程并继续上述反馈方法后的过程?"
感谢所有帮助。