title: Android getting Error while show ProgressDialog
body: <p>I have an Activity where I want to show a ProgressDialog. I override onCreateDialog in my Activity. Everytime the dialog returns in onCreateDialog I get an force-close, saying:</p>
  
  <pre><code>07-13 13:10:11.449: ERROR/AndroidRuntime(8720): android.util.AndroidRuntimeException:     requestFeature() must be called before adding content
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at com.android.internal.app.AlertController.installContent(AlertController.java:199)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at android.app.AlertDialog.onCreate(AlertDialog.java:251)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at android.app.ProgressDialog.onCreate(ProgressDialog.java:176)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at android.app.Activity.createDialog(Activity.java:886)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at android.app.Activity.showDialog(Activity.java:2557)
  07-13 13:10:11.449: ERROR/AndroidRuntime(8720):     at     android.app.Activity.showDialog(Activity.java:2524)
  </code></pre>
  
  <p>the onCreateDialog(int id) looks like this:</p>
  
  <pre><code>    protected Dialog onCreateDialog(int id){
      switch (id) {
      case DOWNLOAD_DIALOG:
          ProgressDialog dialog = new ProgressDialog(ListMapActivity.this);
          dialog.setTitle(getResources().getString(R.string.dialog_download_title));
          dialog.setCancelable(true);
          dialog.setOnCancelListener(new OnCancelListener() {
  
              @Override
              public void onCancel(DialogInterface dialog) {
                  if ((mTask.getStatus().equals(AsyncTask.Status.RUNNING) 
                      || mTask.getStatus().equals(AsyncTask.Status.PENDING)) 
                      &amp;&amp; !mTask.isCancelled()){
                      mTask.cancel(true);
                  }
                  Toast.makeText(getApplicationContext(), R.string.dialog_download_cancel, Toast.LENGTH_LONG).show();
              }
          });         
          TextView tw = new TextView(ListMapActivity.this);
          dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
          LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
          tw.setLayoutParams(params);
          tw.setText(getResources().getString(R.string.dialog_download_text));
          dialog.setContentView(tw);
  
  
          return dialog;
  
      default:
          return null;
      }
  }
  </code></pre>
  
  <p>Note: I tried ProgressDialog.Show(context, title, message) to execute directly instead of showDialog(), with this result:</p>
  
  <pre><code>07-13 13:03:42.910: ERROR/AndroidRuntime(8444): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.view.ViewRoot.setView(ViewRoot.java:531)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.app.Dialog.show(Dialog.java:241)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.app.ProgressDialog.show(ProgressDialog.java:107)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.app.ProgressDialog.show(ProgressDialog.java:90)
  07-13 13:03:42.910: ERROR/AndroidRuntime(8444):     at android.app.ProgressDialog.show(ProgressDialog.java:85)
  </code></pre>
  
  <p>I assume I forget something to initialize. I don't even know where this requestFeature() is been called. Any Idea is welcome</p>
  
  <p>UPDATE:
  I played around a little bit and found out, that everything works again, if I delete these lines:</p>
  
  <pre><code>        LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
          tw.setLayoutParams(params);
          tw.setText(getResources().getString(R.string.dialog_download_text));
          dialog.setContentView(tw);
  </code></pre>
  
  <p>So I'm lost on how to set the Content of this View. It doesn't help, when I create the Main-design in onCreate of my Activity as a member and put this into ProgressDialog. I simply don't get the problem. What is wrong putting a TextView on-the-fly to put it as Content from my Dialog? </p>