Orientation change crashes my app
<p>I have a class for constructing AlertDialog that contains spinner widget. When spinner shows its popup, if I change phone's orientation, my app crashes with exception saying something about leaked window. This matter has been discussed many times before, but only in the context of multithreading. But I have one thread. So what am I doing wrong?</p>

<pre><code>public class ExpenseDialog extends DialogFragment
{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    LayoutInflater factory = LayoutInflater.from(this.getActivity());
    View content = factory.inflate(R.layout.expensedialog, null);

    Spinner spinner = (Spinner) content.findViewById(R.id.catspinner);
    ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
            this.getActivity(), R.array.cats, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    return  new AlertDialog.Builder(this.getActivity())
        .setView(content)
        .setPositiveButton("ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
//some code
            }
        })
        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
//some code
            }
        })
        .create();
}
</code></pre>

<p>}</p>

<p>I show the dialog like this:
(new ExpenseDialog()).show(getSupportFragmentManager(), "expensedialog");</p>
