title: Starting new Thread freezes UI
body: <p>I am working on an app that implements a Web Socket server. I am referring this library - <a href="https://github.com/TooTallNate/Java-WebSocket" rel="nofollow">https://github.com/TooTallNate/Java-WebSocket</a></p>
  
  <p>The problem is that the thread holds up the entire UI. Here is the code - </p>
  
  <pre><code>package com.example.websocket;
  
  import java.net.InetSocketAddress;
  import java.net.UnknownHostException;
  import java.util.Collections;
  
  import java.nio.ByteBuffer;
  
  import org.java_websocket.WebSocket;
  import org.java_websocket.drafts.Draft;
  import org.java_websocket.drafts.Draft_17;
  import org.java_websocket.framing.FrameBuilder;
  import org.java_websocket.framing.Framedata;
  import org.java_websocket.handshake.ClientHandshake;
  import org.java_websocket.server.WebSocketServer;
  
  import android.os.Bundle;
  import android.provider.Settings.Global;
  import android.app.Activity;
  import android.content.Context;
  import android.view.Menu;
  import android.view.View;
  import android.view.inputmethod.InputMethodManager;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      EditText port, msg;
      Button listener, send;
      TextView status;
      int p;
      int count = 0;
      boolean connect = false;
      boolean listen = false;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          msg = (EditText)findViewById(R.id.editText2);
          listener = (Button)findViewById(R.id.button1);
          send = (Button)findViewById(R.id.button2);
          status = (TextView)findViewById(R.id.textView1);
  
          listener.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Thread t = new Thread(new Runnable() {
                      @Override
                      public void run() {
                          try {
                              SimpleServer server = new SimpleServer();
                              server.start();
                              status.setText("Working inside Thread");
                          } catch (UnknownHostException e) {
                              e.printStackTrace();
                          }
                      }   
                  });
  
                  t.start();
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      public class SimpleServer extends WebSocketServer {
  
          public SimpleServer() throws UnknownHostException {
              super(new InetSocketAddress(9998));
              // TODO Auto-generated constructor stub
          }
  
          @Override
          public void onClose(WebSocket arg0, int arg1, String arg2, boolean arg3) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onError(WebSocket arg0, Exception arg1) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onMessage(WebSocket arg0, String arg1) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onOpen(WebSocket arg0, ClientHandshake arg1) {
              status.setText("Working");
  
          }
  
      }
  
  }
  </code></pre>