How to handle listView item changes in managed option menu dialogs?
<p>I create a dialog in my activities <code>onCreateDialog</code> method like this</p>

<pre><code>ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
        android.R.layout.select_dialog_item, android.R.id.text1, items);
dialog = new AlertDialog.Builder(this).setTitle(R.string.dialogTitle).setAdapter(adapter,
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int item) {
                // do something
            }
        }).create();
</code></pre>

<p>The items I want to show in the dialog are in a simple ArrayList</p>

<pre><code>private List&lt;String&gt; items = new ArrayList&lt;String&gt;();
</code></pre>

<p>The dialog is now managed (saved and restored) by my activity - as I understand. Thus it is not recreated every time the user presses the menu button to open the dialog.</p>

<p>According to some user selection on the activity - the item list of the dialog needs to be changed. I thought this would be no great problem but after changing the content of the list I run into the following exception:</p>

<pre><code>06-03 10:55:29.263: ERROR/AndroidRuntime(276): java.lang.IllegalStateException: 
The content of the adapter has changed but ListView did not receive a notification. 
Make sure the content of your adapter is not modified from a background thread, 
but only from the UI thread. [in ListView(16908785, class com.android.internal.app.AlertController$RecycleListView) with Adapter(class android.widget.ArrayAdapter)]
</code></pre>

<p>I debugged the <code>Thread.currentThread().getId()</code> and found it always to be "1" (creation of the dialog and also changing the items list).</p>

<p>How can I handle the item list changes to be noticed by my dialog? Or should I avoid using a "managed" dialog and create it from scratch every time the user opens it?</p>

<p>How can/should I make things work?</p>

<p>Thanks for any suggestions!</p>
