I am creating thread in my onCreate method. I receive data via udp on the thread. For some reason it does not work.

```
private void UdpThread() {
//   server will listen to one client
    try
    {
        Thread udpServerThread = new Thread()
        {
            @Override
            public void run()
            {       
                Log.i("rrr","receivePacket3");
                try
                {
                    while(true)
                    {
                        sleep(1000);
                    Log.i("rrr","receivePacket2");
                    String[] recieved = null;

                    DatagramSocket clientSocket = null;
                    InetAddress IPAddress = null;
                    try {

                        IPAddress = InetAddress.getByName("localhost");
                    } catch (UnknownHostException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    byte[] receiveData = new byte[1500];
                    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                    try {
                        clientSocket = new DatagramSocket(8086);
                        Log.i("rrr","receivePacket");
                        clientSocket.receive(receivePacket);

                        Log.i("rrr","receivePacket1");
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    modifiedSentence = new String(receivePacket.getData());
                    System.out.println("in client receive:" + modifiedSentence);

                    Log.i("Received data",modifiedSentence);
                    clientSocket.close();

                    modifiedSentence =  modifiedSentence.trim();
                    Log.i("Received data",modifiedSentence);
                    }
                } catch (Exception e){
                    Log.e("UDP", "S: Error", e);
                }
            }
        };
        udpServerThread.start();
        //udpServerThread.setPriority(Thread.MAX_PRIORITY);

        Toast.makeText(this,modifiedSentence,Toast.LENGTH_LONG).show();

    }catch (Exception e) {
        // TODO: handle exception
        Log.e("eeeee",""+e);
        e.printStackTrace();
    }
}

```

how should i do when control not return immediately from thread.and wait until the data is not received.