title: Android Dialog and AsyncTask Caused UI to Freeze
body: <p>So, in my Dialog, I have a button which starts an Asynctask downloader to get some file from my server; and that works just fine. However, I want to dismiss my current Dialog and display the ProgressDialog on button clicked. How would I approach this problem?</p>
  
  <p>At the moment, if I click on the button (an element inside my Dialog) the whole UI get froze while the downloader downloading the file from the server. Once the downloader finished its task then the progress dialog will then get shown.</p>
  
  <p>My code looks something like this</p>
  
  <pre><code>MainActivity{
  
      Dialog dialog;
      ProgressDialog progress;
  
      onCreate(){
          dialog = new Dialog(this);
          progress = new ProgressDialog(this);
          dialog.setContentView(Some View Resource With My Button);
          someMethod();
          dialog.show();
      }
  
      someMethod(){
          Button button = (Button) dialog.findViewById(resource of button);
          button.setOnClickListener(new OnClickListener(){
  
              onClick(){
                  dialog.dismiss();
                  progress.show();
                  new DownloaderAsyncTask(progress).execute().get();
              }
  
                      //go to another activity when download finished
  
          });
      }
  
      private class DownloaderAsyncTask extends AsyncTask&lt;Void, Void, Void&gt;{
  
          ProgressDialog progress;
  
          DownloaderAsyncTask(ProgressDialog progress){
              this.progress = progress;
          }
  
          doInBackGround(){
              //Downloading
          }
  
          onPostExecute(){
              //Kill connection
              this.progress.dismiss();
          }
  
      }
  
  }
  </code></pre>
  
  <p>Thanks. Please let me know if you guys need any additional information.</p>