title: How to display a Toast inside a Handler/thread?
body: <p>I want to display a toast once the message is sent to a socket.After this
  "Log.d("ClientActivity", "C: Sent.");"</p>
  
  <p>Whether I need to create a separate thread to display Toast?</p>
  
  <pre><code>public class ClientActivity extends Activity {
  private Handler handler = new Handler();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.client);
      serverIp = (EditText) findViewById(R.id.EditText01);
      message =(EditText) findViewById(R.id.EditText02);
      connectPhones = (Button) findViewById(R.id.Button01);
  
  }
  
      public void Click1(View v) {
          if (!connected) {
              serverIpAddress = serverIp.getText().toString();
              if (!serverIpAddress.equals("")) {
                  Thread cThread = new Thread(new ClientThread());
                  cThread.start();
              }
          }
      }
  
  
  private class ClientThread implements Runnable {
  
      public void run() {
          try {
              InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
              Log.d("ClientActivity", "C: Connecting...");
              Socket socket = new Socket(serverAddr, ServerActivity.SERVERPORT);
              connected = true;
              while (connected) {
                  try {
                      if(i&gt;5)
                      {
  
  
                      } 
                      else
                      {   
                          Log.d("ClientActivity", "C: Sending command.");
                          PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
                                  .getOutputStream())), true);
                          // where you issue the commands
                          message1= message.getText().toString();
                          out.println(message1);
                          i=i+1;
                          Log.d("ClientActivity", "C: Sent.");
                      }    
                  } catch (Exception e) {
                      Log.e("ClientActivity", "S: Error", e);
                  }
              }
              socket.close();
              Log.d("ClientActivity", "C: Closed.");
          } catch (Exception e) {
              Log.e("ClientActivity", "C: Error", e);
              connected = false;
          }
      }
  }
  </code></pre>
  
  <p>}</p>