title: Can't create Dialog Box inside AsyncTask
body: <p>I am not able to create Dialog box inside AsyncTask. Can someone help here? I am getting error "android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application". </p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public class MainActivity extends Activity {
              protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_main);
                      AsyncTaskTest at=new AsyncTaskTest();
                      at.execute();
              }   
  
              public class AsyncTaskTest extends AsyncTask&lt;Void, String, Void&gt; {
                      protected Void doInBackground(Void... vd){
                              try{
                                      String desc = "Show Dialog without error";
                                      publishProgress(desc);
                              }catch(Exception e){
                                      publishProgress("Error: "+e.toString());
                              }
                              return null;
                      }
                      protected void onProgressUpdate(String... msg) {
                              showDialog(msg[0]);
                      }
                      private void showDialog(String msg){
                      final AlertDialog.Builder alertBox = new AlertDialog.Builder(new ContextThemeWrapper(getApplicationContext(), android.R.style.Theme_Dialog));
                      alertBox.setMessage(msg);
                      alertBox.setCancelable(false)
                                      .setPositiveButton("Ok", new DialogInterface.OnClickListener(){
                                      public void onClick(DialogInterface dialog,int id){
                                              dialog.cancel();
                                      }
                              }).show();
                      }
              }
      }
  </code></pre>