-1

I have inside onCreate method code like this

    AlertDialog.Builder builder = new AlertDialog.Builder(
                    Ex.this);
            builder.setMessage(
                    getResources().getString(R.string.title))
                    .setPositiveButton(
                            getResources().getString(R.string.ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                }
                            })
                    .setNegativeButton(
                            getResources().getString(R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                }
                            }).create().show();

but I get leaked window error always. Can anybody tell me what is wrong ? I tried to replace Ex.this with getApplicationContext() but that didn't help.

Damir
  • 54,277
  • 94
  • 246
  • 365
  • Following links may be useful to you [http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added][1] [http://stackoverflow.com/questions/5181508/activity-has-leaked-window-com-android-internal-policy-impl-phonewindowdecorvie][2] [1]: http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added [2]: http://stackoverflow.com/questions/5181508/activity-has-leaked-window-com-android-internal-policy-impl-phonewindowdecorvie – Chandrapal Yadav Feb 01 '12 at 09:04

1 Answers1

0

Don't call dialog.show() directly. Instead, go through onCreateDialog().

See API Demos for examples: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html

chiuki
  • 14,580
  • 4
  • 40
  • 38