title: Running ProgressDialog in Thread in Android
body: <p>I want to run a ProgressDialog(Spinner) when I send and receive some packets in a bluetooth device when a button is pressed. Here is the code </p>
  
  <pre><code> button.setOnClickListener(new OnClickListener() {
  
            public void onClick(View v) {
  
  
            Handler handler = new Handler();
            Runnable r=new Runnable()
            {
                public void run()
                {
                      dialog1 = ProgressDialog.show(Test.this, "",
                             "Receiving. Please wait...", true);
  
  
  
                }
            };
            handler.post(r);
  
            blueToothServer.getDevicebyMac();
            blueToothServer.rfSocket();
            blueToothServer.cancelDiscovery();
            blueToothServer.connectSocket();
            //toastMessage("Socket connected");
            blueToothServer.ipstream();
            blueToothServer.opStream();
            blueToothServer.SendnRXDataToBTServer(2, "some String");
            String Result1 = blueToothServer.response(1);
            tv1.setText("Temperatue : " + Result1);
            dialog1.dismiss();
   }
  </code></pre>
  
  <p>But I'm not getting the ProgressDialog. But I can able to send and receive the packets. But when I comment the blueToothServer operations, I'm getting the progress dialog. Please explain me the situation where I can get both. Thank You.</p>