AlertDialog 中的链接泄漏窗口?
我在警报对话框中创建了一个可链接文本,并使 TextView 可单击,如下所示:
final SpannableString noRecords = new SpannableString("Sorry, no records could be found, please try again, or contact us at 867-5309");
Linkify.addLinks(noRecords);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Records Found")
.setMessage(noRecords)
.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
((TextView)alert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
这有效,但是当单击它时,它会在 logcat 中产生错误:
08-19 19:40:55.753: 错误/WindowManager(5886): 活动 com.blah.MainActivity 已泄漏窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 那个 最初添加于此处 08-19 19:40:55.753: 错误/WindowManager(5886):android.view.WindowLeaked:活动 com.blah.MainActivity 已泄漏窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 那个 最初添加在这里
我认为这是因为在单击链接之前警报没有被解除。 有什么办法解决这个问题吗?我不想抛出任何错误。
I've created a linkable text in an alert dialog, and make the TextView clickable, like this:
final SpannableString noRecords = new SpannableString("Sorry, no records could be found, please try again, or contact us at 867-5309");
Linkify.addLinks(noRecords);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Records Found")
.setMessage(noRecords)
.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
((TextView)alert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
This works, however when it's clicked it produces an error in logcat:
08-19 19:40:55.753: ERROR/WindowManager(5886): Activity
com.blah.MainActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 that
was originally added here 08-19 19:40:55.753:
ERROR/WindowManager(5886): android.view.WindowLeaked: Activity
com.blah.MainActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 that
was originally added here
I think this is because the alert is not dismissed before the link is clicked.
Is there any way around this? I'd prefer not to be throwing any errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在活动被销毁之前处理对话框,您可以覆盖 onDestroy() 事件
希望有帮助
If you want to dispose the dialog before the activity is destroyed, you can override the onDestroy() event
Hope that helps