Android - How to show AlertDialog before finishing activity?
<p>I'm trying to implement this code</p>

<pre><code>    if(someCondition){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("message")
        .setPositiveButton("Yes", this)
        .setNegativeButton("No", this);
        builder.show();
    }
    finish();
</code></pre>

<p>The problem is that the activity calls finish() before dialog is shown up so it throws the following exception</p>

<pre><code>MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40704090 that was originally added here
</code></pre>

<p>How to handle that?</p>
