1.表现形式

2.尝试处理方案

1).主动让相关表死锁,导致界面持续等待响应
2).运行中的代码检测到异常
  1. Android.Views.WindowManagerBadTokenException: 'Unable to add window -- token android.os.BinderProxy@d399ebb is not valid; is your activity running?'

报错代码

  1. AlertDialog.Builder builder = new AlertDialog.Builder(context);
  2. builder.SetTitle("消息");
  3. builder.SetIcon(Android.Resource.Drawable.IcDialogAlert);
  4. builder.SetMessage(message);
  5. builder.SetPositiveButton("确定", (EventHandler<DialogClickEventArgs>)null);
  6. AlertDialog dialog = builder.Create();
  7. dialog.Show();//这一行
  8. Button btnDialog = dialog.GetButton((int)DialogButtonType.Positive);
  9. btnDialog.RequestFocus();
  10. btnDialog.Click += delegate
  11. {
  12. dialog.Dismiss();
  13. };
3).百度原因

当页面处于等待状态时,若关闭了当前页面,那么dialog.Show()时,因为Activity已经被销毁,导致运行报错

4).解决方案

加try catch捕获异常并记录本地文件日志

  1. try
  2. {
  3. dialog.Show();
  4. }
  5. catch (Exception ex)
  6. {
  7. string contextString = context.ToString();
  8. string activityName = contextString.Substring(contextString.LastIndexOf(".") + 1, (contextString.IndexOf("@") - contextString.LastIndexOf(".") - 1));
  9. LogHelper.RunLogger(activityName, "ShowDialogMessage:" + ex.ToString());
  10. return;
  11. }
文档更新时间: 2020-10-20 17:23   作者:谢伟凡