Application Crash Reporting for Android

ACRA is a Google library that allows your Android applications to automatically log unhandled exceptions or application crashes to a Google document and/or display Toast notifications.

To use it, you’ll need to create an Application class at the root of your Android application. This class will be used to log any uncaught or unhandled Exceptions, and will contain ACRA’s configuration.

Here’s a sample Application class:
[java]
package com.justinschultz.android;

import java.lang.Thread.UncaughtExceptionHandler;

import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;

import android.app.Application;
import android.util.Log;

@ReportsCrashes(formKey = "YOURFORMKEY")
public class MyApplication extends Application implements UncaughtExceptionHandler
{
private static MyApplication instance;

public MyApplication()
{
instance = this;
Thread.setDefaultUncaughtExceptionHandler(this);
}

@Override
public void onCreate()
{
ACRA.init(this);
super.onCreate();
}

public static MyApplication getInstance()
{
return instance;
}

@Override
public void uncaughtException(Thread thread, Throwable ex)
{
Log.i("Error: ", (ex == null || ex.getMessage() == null) ? "Unknown" : ex.getMessage());
}

}
[/java]

Here’s how to generate a form key and complete the configuration.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *