Android Alert dialog closes without waiting
<p>In my app i used an alert dialog to display warning message and wait for yes/no.  But alert dialog display without waiting and disappears.  Here the code shown below</p>

<pre><code>            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Delete Macro");
            builder.setMessage(" " + mMacroName + "\n\nAre you sure ?");

            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                   // some tasks
                   }
               });

            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       finish();
                   }
               });

            AlertDialog dialog = builder.create();
            builder.show();
</code></pre>

<p><strong>logcat received</strong> shows some leakage</p>

<pre><code> 04-02 15:09:32.954: E/WindowManager(279): Activity com.mtxlabs.hat.setup.MacroProp has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43ea4d50 that was originally added here
 04-02 15:09:32.954: E/WindowManager(279): android.view.WindowLeaked: Activity com.mtxlabs.hat.setup.MacroProp has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43ea4d50 that was originally added here
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.ViewRoot.&lt;init&gt;(ViewRoot.java:247)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
 04-02 15:09:32.954: E/WindowManager(279):  at android.app.Dialog.show(Dialog.java:241)
 04-02 15:09:32.954: E/WindowManager(279):  at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
 04-02 15:09:32.954: E/WindowManager(279):  at com.mtxlabs.hat.setup.MacroProp.onSaveButtonClick(MacroProp.java:218)
 04-02 15:09:32.954: E/WindowManager(279):  at java.lang.reflect.Method.invokeNative(Native Method)
 04-02 15:09:32.954: E/WindowManager(279):  at java.lang.reflect.Method.invoke(Method.java:521)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.View$1.onClick(View.java:2067)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.View.performClick(View.java:2408)
 04-02 15:09:32.954: E/WindowManager(279):  at android.view.View$PerformClick.run(View.java:8816)
 04-02 15:09:32.954: E/WindowManager(279):  at android.os.Handler.handleCallback(Handler.java:587)
 04-02 15:09:32.954: E/WindowManager(279):  at android.os.Handler.dispatchMessage(Handler.java:92)
 04-02 15:09:32.954: E/WindowManager(279):  at android.os.Looper.loop(Looper.java:123)
 04-02 15:09:32.954: E/WindowManager(279):  at android.app.ActivityThread.main(ActivityThread.java:4627)
 04-02 15:09:32.954: E/WindowManager(279):  at java.lang.reflect.Method.invokeNative(Native Method)
 04-02 15:09:32.954: E/WindowManager(279):  at java.lang.reflect.Method.invoke(Method.java:521)
 04-02 15:09:32.954: E/WindowManager(279):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 04-02 15:09:32.954: E/WindowManager(279):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 04-02 15:09:32.954: E/WindowManager(279):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>please help me to solve this problem</p>
