0

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.

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
pedro.olimpio
  • 1,478
  • 2
  • 22
  • 43
  • 2
    Why do you even use a `Runnable` for this? `AsyncTask` does the desired job. – Murat Karagöz Nov 22 '16 at 12:33
  • +1 for Murat, also why do you want to back to the thread? why don't you show the toast at `feedbackMessage()` ? and in case you want to do another thread-things , just start a new thread also from `feedbackMessage()` – Yazan Nov 22 '16 at 12:48
  • It's a example of the process, I want to control the process, the behavior i'll implement is: After receive the feedback I'll send another UDP message containing the next step of the firmware. – pedro.olimpio Nov 22 '16 at 13:04
  • Really, the question is duplicated. The post above solve my problem. Thanks for all help – pedro.olimpio Nov 22 '16 at 13:37

0 Answers0