Question

I'm using ACRA in my android application.

But I find that when exception happens within Application#onCreate() method,it only save the report file,rather than raising the dialog to send it.

It there something wrong with my code?

@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();
        }
}
Was it helpful?

Solution

The onCreate of the Application is called before any Activity is created and does not have a UI, therefore ACRA cannot display a dialog. From the android docs for 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().

So, be sure to call super.onCreate(), which your example above is missing, and you should not be doing a whole lot in there that would cause exceptions.

OTHER TIPS

I'm seeing two problems with your code.

  1. You don't call super.onCreate() after initializing ACRA
  2. Your class should have tha annotation @Reportscrashes even if the parameters are set at runtime. Otherwise you will get an error in logcat saying ACRA#init called but no ReportsCrashes annotation on Application

Also, I'm not sure if the Application can show a dialog because it has no UI layout associated with it. Toast reporting works fine if you change both points above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top