title: Android progress dialog not closing
body: <p>I want to show progress dialog in the page layout. I implemented in the following code. Progress Dialog is not closed and it keeps running.When I click an image in the previous page it will navigate to the next layout and I want this layout to show progress dialog before all the data is downloaded from server and show it in the list of the current layout. Progress dialog is displayed and list is displayed in the background but progress dialog keeps on running and it does not get closed. I don't know where i am going wrong. Help please.</p>
  
  <pre><code>ProgressDialog pg;
  String[] ar;
  public void onCreate(Bundle savedInstanceState) 
  {
  
           super.onCreate(savedInstanceState);
           setContentView(R.layout.filename);
           pg=ProgressDialog.show(this, "ABC", "Downloading .....",true);  
  
           Thread dt= new Thread(new Runnable() 
          {
              public void run() 
              {
                  try
                  {
                       String addr=Util.url;
                       URL url = new URL(urlname);
                       HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                       urlConnection.setConnectTimeout(5000);             
                       InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                       BufferedReader r = new BufferedReader(new InputStreamReader(in));
                       String x = "";
                       String total = "";
                       int i=0;
                       ArrayList&lt;String&gt; content = new ArrayList();
                       while((x = r.readLine()) != null)
                      {
                          content.add(x);
                      }
                      in.close();
                      r.close();
                      ar= content.toArray(new String[content.size()]);
  
                  }
                  catch(Exception e1){
                       handler.sendEmptyMessage(0);
                  }
  
              }
  
          });
  
          dt.start();
          try{
              dt.join();
  
          }catch(Exception e){
              handler.sendEmptyMessage(0);
          }
  
      try{   
          if(ar[0].toString().trim()!="")
          {
               android.view.Display display1 = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
               TableLayout tbl1 = (TableLayout)findViewById(R.id.tableLayout2);
  
               TableRow newRow1 = (TableRow) new TableRow(this);
               TextView txt=(TextView) new TextView(this);
               txt.setText("No");
               txt.setGravity(Gravity.LEFT);
               txt.setTextColor(Color.RED);
               txt.setTextSize(18);
  
               TextView txt1=(TextView) new TextView(this);
               txt1.setText("NAME");
               txt1.setTextColor(Color.RED);
               txt1.setTextSize(18);
               txt1.setGravity(3);
  
               TextView txt2=(TextView) new TextView(this);
               txt2.setText("DATE");
  
               txt2.setTextColor(Color.RED);
               txt2.setTextSize(18);
               txt.setGravity(3);
  
               TextView txt3=(TextView) new TextView(this);
               txt3.setText("VALUE");
               txt3.setTextColor(Color.RED);
               txt3.setTextSize(18);
               txt3.setGravity(Gravity.RIGHT);
  
  
               txt.setWidth((int)(display1.getWidth()/4));
               txt1.setWidth((int)(display1.getWidth()/4));
               txt3.setWidth((int)(display1.getWidth()/4)); 
               txt2.setWidth((int)(display1.getWidth()/4));
  
  
               newRow1.addView(txt2);
               newRow1.addView(txt);
               newRow1.addView(txt1);
               newRow1.addView(txt3);
               tbl1.addView(newRow1);
  
              for(int t=0;t&lt;(ar.length);t++)
              {
              android.view.Display display = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
              TableLayout tbl = (TableLayout)findViewById(R.id.tableLayout1);
              TableRow newRow = (TableRow) new TableRow(this);
              newRow.setClickable(true);
              TextView tx=(TextView) new TextView(this);
              String temp=ar[t].toString();
              tx.setText(temp);
              tx.setTextColor(Color.WHITE);
              tx.setGravity(Gravity.LEFT);
              tx.setTextSize(15);
  
              t=t+1;
  
              TextView tx1=new TextView(this);
              tx1.setText(ar[t].toString());
              tx1.setGravity(Gravity.LEFT);
              tx1.setTextColor(Color.WHITE);
              tx1.setTextSize(15);
  
  
              t=t+1;
  
              TextView tx2=new TextView(this);
              tx2.setText(ar[t].toString());
              tx2.setGravity(Gravity.LEFT);
              tx2.setTextColor(Color.WHITE);
              tx2.setTextSize(15);
  
              t=t+1;
  
              TextView tx3=new TextView(this);
              tx3.setText(ar[t].toString());
              tx3.setGravity(Gravity.RIGHT);
              tx3.setTextColor(Color.WHITE);
              tx3.setTextSize(15);
  
              tx3.setWidth((int)(display.getWidth()/4));
              tx.setWidth((int)(display.getWidth()/4));
              tx1.setWidth((int)(display.getWidth()/4));
              tx2.setWidth((int)(display.getWidth()/4));
  
              newRow.addView(tx);
              newRow.addView(tx2);
              newRow.addView(tx1);
              newRow.addView(tx3);
  
               newRow.setId(t);
  
              tbl.addView(newRow);
              }
  
          }
      }
      catch(Exception e){
          pg.dismiss();
          handler.sendEmptyMessage(0); 
      }
  
  }
  private Handler handler = new Handler() {
      @Override 
            public void handleMessage(Message msg) {
  
          Toast.makeText(this,"Network not available!.... ", Toast.LENGTH_LONG).show();
  }
  };
  </code></pre>