【问题标题】:Leaked window when try to show Dialog尝试显示对话框时泄漏的窗口
【发布时间】:2012-02-01 08:54:44
【问题描述】:

我里面有这样的onCreate方法代码

    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();

但我总是收到 leaked window 错误。谁能告诉我出了什么问题?我试图用 getApplicationContext() 替换 Ex.this,但这没有帮助。

【问题讨论】:

标签: android android-widget


【解决方案1】:

不要直接拨打dialog.show()。相反,请通过onCreateDialog()

请参阅 API 演示以获取示例:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-29
    • 2017-01-02
    • 2013-05-23
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多