android - ACRA 无法处理 Application#onCreate() 中发生的异常

标签 android acra

我正在使用 ACRA在我的安卓应用程序中。

但我发现当 Application#onCreate() 方法中发生异常时,它只保存报告文件,而不是弹出对话框来发送它。

我的代码有问题吗?

@ReportsCrashes(formKey="")
public class MyAndroidApplication extends Application
{
        public void onCreate()
        {
            ACRAConfiguration config = ACRA.getConfig();
            config.setMailTo("test@test.com");
            config.setResToastText(R.string.acra_toast);
            config.setResDialogText(R.string.acra_dlg_txt);
            config.setResDialogCommentPrompt(R.string.acra_dlg_comment_prpmpt);
            try
            {
                config.setMode(ReportingInteractionMode.DIALOG);
            }
            catch (ACRAConfigurationException e)
            {
                logger.error("fail to config ACRA", e);
                return;
            }
            ACRA.setConfig(config);
            ACRA.init(this);
            someMethodThrowsException();
        }
}

最佳答案

ApplicationonCreate 在创建任何Activity 之前调用,并且没有UI,因此ACRA 无法显示对话框。来自android docs对于 onCreate

Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

因此,请务必调用 super.onCreate(),上面的示例中缺少它,并且您不应该在其中做太多会导致异常的事情。

关于android - ACRA 无法处理 Application#onCreate() 中发生的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14334168/

相关文章:

android - 通过 url 下载图片,或者使用 base64 转换

android - 如何使用 Kotlin 在 Android 中保存开关设置

android - 在 Appium 中,通过不是 View id 字段的唯一 id 查找 Android View

android - 双android版本的eclipse结构

java - 如何禁用 ACRA 的日志记录

android - 带有 StateListDrawable 的 ImageView 不起作用

android - 运行时异常被 ACRA 捕获,不会显示在 Logcat 上

Android 应用程序崩溃,但不会重新启动 - 从应用程序中的另一点恢复

android - ACRA LogCat 参数未按预期工作

android - ACRA 和 proguard,行号不正确