Prevent onCreateDialog being called when process is killed then relaunched
<p>I have an Activity with ProgressDialog being updated by an AsyncTask. I am using onCreateDialog to setup the dialog. The AsyncTask is writing to the SDCard. During normal scenarious (rotation, going to background, etc.) I have no issues.</p>

<p>The problem is that the dialog gets recreated if the process gets killed. Thus, I end up with a "newly" opened activity and a dialog that is not supposed to be shown at all because there is no AsyncTask set up to update it.</p>

<p>For example in case when SD card gets ejecter then the Reaper comes and kills the process (no onDestroy, noPause, noResume has been called by the framework). When, however, the application is resumed (for example from the recently used applications) there is no clue that there is no AsyncTask and I am forced to show the dialog. I cannot return null in onCreateDialog, because the app will crash.</p>

<p>How can I prevent a dialog to be recreated after the process is killed?</p>

<p>Example:</p>

<pre>
- Activity gets shown
    - onCreateDialog/onPrepareDialog show a progress dialog
      - AsyncTask gets started exporting to SD card
=> SD card gets unmounted
- Process is killed
- User selects the application from task switched
- Activity gets created as new
=> Android calls onCreateDialog/onPrepareDialog with the previously shown dialog ID
</pre>

<p>By the time the activity is recreated as new there is no AsyncTask, there is even no SD card. Still, Android insist that I show a dialog.</p>

<p>How can I prevent onCreate/PrepareDialog methods to be called during the recreate? Or the only choice is to bring up an error dialog instead.</p>
