title: Android RuntimeException onCreateDialog did not create a dialog for id
body: <p>I've an application that you can show and close several Dialogs with:</p>
  
  <pre><code>showDialog(...)
  removeDialog(...)
  </code></pre>
  
  <p>I play a little bit with the application and when there is no any Dialog on the screen, I press the menu button and I go to the main android screen.</p>
  
  <p>After a while, I enter again into my application and sometimes, I get this RuntimeException:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 4
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
      at android.app.ActivityThread.access$2200(ActivityThread.java:126)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:123)
      at android.app.ActivityThread.main(ActivityThread.java:4595)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:521)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
      at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 4
      at android.app.Activity.createDialog(Activity.java:878)
      at android.app.Activity.restoreManagedDialogs(Activity.java:867)
      at android.app.Activity.performRestoreInstanceState(Activity.java:815)
      at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2565)
      ... 11 more
  </code></pre>
  
  <p>Any idea?</p>
  
  <p>Thank you very much.</p>
  
  <p>UPDATE, more information:</p>
  
  <p>The current onCreateDialog implementation is:</p>
  
  <pre><code>protected Dialog onCreateDialog(int id){
   Builder b = new AlertDialog.Builder(this);
   if(id == 4){
    b.setMessage(...);
    b.setItems(items, new DialogInterface.OnClickListener(){
     public void onClick(DialogInterface dialog, int which){
      Intent i = new Intent(Current.this, Another.class);
      startActivity(i);
     }
    });
    return b.create();
   }
   return null;
  }
  </code></pre>
  
  <p>In order to call this function I do:</p>
  
  <pre><code>removeDialog(4);
  showDialog(4);
  </code></pre>