尝试显示对话框时泄漏窗口
我有这样的 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 但这没有帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要直接调用
dialog.show()
。相反,请执行onCreateDialog()
。请参阅 API 演示以获取示例: http ://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html
Don't call
dialog.show()
directly. Instead, go throughonCreateDialog()
.See API Demos for examples: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html