【问题标题】:Android debugging - How to display UI thread exception/errors categorically as dialogAndroid 调试 - 如何将 UI 线程异常/错误分类显示为对话框
【发布时间】:2015-03-12 11:55:10
【问题描述】:

有没有办法在每次发生时,在代码中的任何位置,在对话框中明确显示 UI 线程上的异常(使我的应用程序停止)?

为什么? :在我的手机未连接到 Android Studio(并且我看不到 logcat)时帮助我测试我的应用

因此,每次 UI 线程发生异常时,我都可以看到堆栈跟踪显示为对话框,而不是“MyApp 刚刚停止工作”然后转到 logcat 并查找错误

【问题讨论】:

  • 您是否在问是否可以使用刚刚崩溃的应用程序(消息很清楚,应用程序“已停止工作”)从崩溃中恢复并显示对话框?
  • 是的,没错。应该有一个应用程序级别的异常处理程序(或类似的东西),它检测应用程序何时崩溃,获取导致崩溃发生的错误日志(异常字符串),并显示为一个对话框(可能是可滚动的 - 因为它会很多文字)

标签: android debugging exception android-studio android-debug


【解决方案1】:

您可以将堆栈跟踪写入字符串,然后像对话框一样显示它,例如:

StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
DialogUtils.showErrorDialog(errors.toString()); // call here your's dialog

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多