title: dialog box causes app to crash
body: <p>This is the issue, I have a dialog box that only appears the first time a user installs my app. After testing with my own device I see that simply doing nothing after the box pops up causes the app to crash. My intention is to have this dialog box be the first thing that the user sees after installing the app. It does appear, but causes the app to crash if the user does not press a button within about 3 seconds. However, if I relaunch the app after the crash then the box is displayed forever until the user presses a button which is my intended goal for the box.</p>
  
  <p>Here is the logcat:</p>
  
  <pre><code>12-13 15:25:28.625: ERROR/WindowManager(15315): Activity com.nick.simplequiz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41506ff0 V.E..... R....... 0,0-684,679} that was originally added here
      android.view.WindowLeaked: Activity com.nick.simplequiz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41506ff0 V.E..... R....... 0,0-684,679} that was originally added here
      at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:458)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
      at android.app.Dialog.show(Dialog.java:286)
      at com.nick.simplequiz.MainActivity.onCreate(MainActivity.java:216)
      at android.app.Activity.performCreate(Activity.java:5165)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1103)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
      at android.app.ActivityThread.access$600(ActivityThread.java:162)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:158)
      at android.app.ActivityThread.main(ActivityThread.java:5751)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
      at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>and this is the line where the error happens according to the logcat:</p>
  
  <pre><code>alertDialog.show();
  </code></pre>
  
  <p>What could be causing this to happen?</p>
  
  <p>This is the code, inside the <code>onCreate</code> method:</p>
  
  <pre><code>AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                  context);
  
      alertDialogBuilder.setCancelable(false);
      alertDialogBuilder.setTitle("...."); //Set the title of the box
      alertDialogBuilder.setMessage("....");
      alertDialogBuilder.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              dialog.cancel(); //when they click dismiss we will dismiss the box
              SharedPreferences.Editor edit2 = sp.edit();
              edit2.putInt("SHOW", 1);
              edit2.commit();
          }
      });
      alertDialogBuilder.setNegativeButton("", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
              .......
          }
      });
      AlertDialog alertDialog = alertDialogBuilder.create(); //create the box
      alertDialog.show(); //*************error happens here
  </code></pre>