【问题标题】:How do I show a dialog after the Thread has encountered an uncaught exception?线程遇到未捕获的异常后如何显示对话框?
【发布时间】:2009-11-27 16:16:18
【问题描述】:

我想检测 uncaught exception 何时在我的 Android 应用中发生。

一旦检测到,我想显示一个确认对话框

如何显示此确认对话框?当我尝试各种技术时,UI 没有响应并且似乎被冻结了。

我的代码对此作出响应:

new CatchAllExceptionHandler(this) is my custom handler
Thread.setDefaultUncaughtExceptionHandler(new CatchAllExceptionHandler(this));

我试过CatchAllExceptionHandler的这两种实现方式:

  1. 显示警报对话框
  2. 启动一个活动,然后在 onCreate 之后显示一个警报对话框

这两种方法都失败了。

所以我的问题是:如何让确认对话框正确显示?

【问题讨论】:

  • 如果您将一些代码放入写入日志文件的处理程序中,您会看到那里的输出吗?

标签: android exception


【解决方案1】:

您可能试图在非 UI 线程上执行 UI 操作。使用任何可用的技术(HandlerHandler#postView#postActivity#runOnUiThreadAsyncTask#onPostExecute)来安排您的 UI 工作在 UI 线程上完成。

【讨论】:

    猜你喜欢
    • 2017-07-22
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    相关资源
    最近更新 更多