proper handling AlertDialog when configration change
<p>I saw many solution to maintain <code>AlertDialog</code> and most of them doesn't work probably when screen dim down. but this which i made works fine is there any other light weight way to do that , I want to use it inside <code>Fragment</code> from <code>ACL</code> . </p>

<pre><code> public class Test extends Activity {

    AlertDialog dialog;
    boolean dialog_should_be_shown = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button btn = new Button(this);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                createDialog();
            }
        });
        setContentView(btn);
        if (savedInstanceState != null) {
            dialog_should_be_shown = savedInstanceState.getBoolean("flag",
                    false);
        }
    }

    private void createDialog() {
        dialog = new AlertDialog.Builder(Test.this).setMessage("HEllo")
                .setCancelable(true).create();
        dialog.show();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
        outState.putBoolean("flag", dialog_should_be_shown);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (dialog_should_be_shown) {
            createDialog();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (dialog != null &amp;&amp; dialog.isShowing()) {
            dialog_should_be_shown = true;
            dialog.dismiss();
        } else {
            dialog_should_be_shown = false;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_test, menu);
        return true;
    }
}
</code></pre>

<p>UPDATE : 
I dont want to retain <code>Framgnet</code> in memory. </p>
