我正在使用 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();
}
}
最佳答案
Application
的onCreate
在创建任何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/