1.表现形式
2.尝试处理方案
1).主动让相关表死锁,导致界面持续等待响应
2).运行中的代码检测到异常
Android.Views.WindowManagerBadTokenException: 'Unable to add window -- token android.os.BinderProxy@d399ebb is not valid; is your activity running?'
报错代码
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.SetTitle("消息");
builder.SetIcon(Android.Resource.Drawable.IcDialogAlert);
builder.SetMessage(message);
builder.SetPositiveButton("确定", (EventHandler<DialogClickEventArgs>)null);
AlertDialog dialog = builder.Create();
dialog.Show();//这一行
Button btnDialog = dialog.GetButton((int)DialogButtonType.Positive);
btnDialog.RequestFocus();
btnDialog.Click += delegate
{
dialog.Dismiss();
};
3).百度原因
当页面处于等待状态时,若关闭了当前页面,那么dialog.Show()时,因为Activity已经被销毁,导致运行报错
4).解决方案
加try catch捕获异常并记录本地文件日志
try
{
dialog.Show();
}
catch (Exception ex)
{
string contextString = context.ToString();
string activityName = contextString.Substring(contextString.LastIndexOf(".") + 1, (contextString.IndexOf("@") - contextString.LastIndexOf(".") - 1));
LogHelper.RunLogger(activityName, "ShowDialogMessage:" + ex.ToString());
return;
}
文档更新时间: 2020-10-20 17:23 作者:谢伟凡