title: progressBar in AsynchTask causes crash, "Unable to add window -- token null is not for an application"
body: <p>in my App, i am trying to show a busy indicator while i am connecting to a server, so I created <code>AsynchTask</code> with <code>dialog</code>with <code>progressBar</code>.</p>
  
  <p>At run time when i try to connect to the server, the App crashs, out of the below posted <code>LogCat</code> it seems it is a problem with the <code>dialog</code> but i do not know what causes the error exactly.</p>
  
  <p>the app is in LandScape mode with <code>navigationdrawer</code></p>
  
  <p>please have a look at the <code>onPreExecute</code> method and the <code>logcat</code> errors.</p>
  
  <p><strong>onPreExecute</strong>:</p>
  
  <pre><code>@Override
      protected void onPreExecute() {
          // TODO Auto-generated method stub
          super.onPreExecute();
          dialog = new Dialog(getApplicationContext());
          dialog.setCancelable(false);
          //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setContentView(R.layout.progressdialog);
          progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar1);
          dialog.show();
      }
  </code></pre>
  
  <p><strong>LogCat</strong>:</p>
  
  <pre><code> E/AndroidRuntime(20575): Process: com.example.mqtt_designlayout_02, PID: 20575
   E/AndroidRuntime(20575): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
   E/AndroidRuntime(20575):   at android.view.ViewRootImpl.setView(ViewRootImpl.java:731)
   E/AndroidRuntime(20575):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
   E/AndroidRuntime(20575):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
   E/AndroidRuntime(20575):   at android.app.Dialog.show(Dialog.java:288)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity$BusyIndicator.onPreExecute(MainActivity.java:768)
   E/AndroidRuntime(20575):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
   E/AndroidRuntime(20575):   at android.os.AsyncTask.execute(AsyncTask.java:535)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity.connectionIndicator(MainActivity.java:468)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity.MQTTConnect(MainActivity.java:460)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity.MQTT_Connection_Module(MainActivity.java:558)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity.access$0(MainActivity.java:548)
   E/AndroidRuntime(20575):   at com.example.mqtt_designlayout_02.MainActivity$1.onClick(MainActivity.java:79)
   E/AndroidRuntime(20575):   at android.view.View.performClick(View.java:4626)
   E/AndroidRuntime(20575):   at android.view.View$PerformClick.run(View.java:19293)
   E/AndroidRuntime(20575):   at android.os.Handler.handleCallback(Handler.java:733)
   E/AndroidRuntime(20575):   at android.os.Handler.dispatchMessage(Handler.java:95)
   E/AndroidRuntime(20575):   at android.os.Looper.loop(Looper.java:157)
   E/AndroidRuntime(20575):   at android.app.ActivityThread.main(ActivityThread.java:5293)
   E/AndroidRuntime(20575):   at java.lang.reflect.Method.invokeNative(Native Method)
   E/AndroidRuntime(20575):   at java.lang.reflect.Method.invoke(Method.java:515)
   E/AndroidRuntime(20575):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
   E/AndroidRuntime(20575):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
   E/AndroidRuntime(20575):   at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>i am sorry but i am banned from and. so your solution is just,
  Change following line,
  dialog = new Dialog(<strong>getParent()</strong>);</p>