title: show and dismiss progress dialog while running a thread in android
body: <p>I have a method in my activity to download a set of files. This downloading is taking place when I start a new activity. I have used threads, because it downloads completely whereas AsyncTask may sometimes fail to download all files, it may get stuck in between.</p>
  
  <p>Now, a black screen is shown when the downloading takes place. I want to show it within a ProgressDialog so that user may feel that something is getting downloaded.</p>
  
  <p>I have added a ProgressDialog, but its not showing. Can anyone tell where did I go wrong?</p>
  
  <p>Below is my code:</p>
  
  <p>Inside <code>onCreate()</code> I have written:</p>
  
  <pre><code>downloadFiles();
  
  private boolean downloadFiles() {
      showProgressDialog();
      for(int i = 0; i &lt; filesList.size();i++) {
          Thread thread = new Thread(new Runnable() {    
              @Override
              public void run() {
                  //downloading code
           });
           thread.start();
           thread.run();
      }
      dismissProgressDialog();
      return true;
  }
  
  //ProgressDialog progressDialog; I have declared earlier.
  private void showProgressDialog() { 
      progressDialog = new ProgressDialog(N12ReadScreenActivity.this);
      progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      progressDialog.setMessage("Downloading files...");
      progressDialog.show();
  }
  
  private void dismissProgressDialog() {
      if(progressDialog != null)
          progressDialog.dismiss();
  }
  </code></pre>