I need to develop an asynchronous network communication and I'm a little bit confused about how can I do that.
I have this 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();
}
});
}
};
and I have this method:
public static void feedbackMessage(byte[] buffer){
//Here I'll receive the UDP answer as well...
}
My question is: "How can I "pause" the process after firmwareHandler.UDPSend(bufferIsAlive);
and continue the process after the feedback method above?"
Thanks for all of the help.