public class ErrorReporter
extends java.lang.Object
implements java.lang.Thread.UncaughtExceptionHandler
The ErrorReporter is a Singleton object in charge of collecting crash context
data and sending crash reports. It registers itself as the Application's
Thread default Thread.UncaughtExceptionHandler
.
When a crash occurs, it collects data of the crash context (device, system, stack trace...) and writes a report file in the application private directory. This report file is then sent:
ReportsCrashes.mode()
is set to
ReportingInteractionMode.SILENT
or
ReportingInteractionMode.TOAST
,ReportsCrashes.mode()
is set
to ReportingInteractionMode.NOTIFICATION
.If an error occurs while sending a report, it is kept for later attempts.
Modifier and Type | Method and Description |
---|---|
void |
addCustomData(java.lang.String key,
java.lang.String value)
Deprecated.
|
void |
checkReportsOnApplicationStart()
Deprecated.
since 4.8.0 No replacement.
|
void |
clearCustomData()
Removes all key/value pairs from your reports custom data field.
|
java.lang.String |
getCustomData(java.lang.String key)
Gets the current value for a key in your reports custom data field.
|
void |
handleException(java.lang.Throwable e)
Send a report for a
Throwable with the reporting interaction mode
configured by the developer, the application is then killed and restarted
by the system. |
void |
handleException(java.lang.Throwable e,
boolean endApplication)
Send a report for a
Throwable with the reporting interaction mode
configured by the developer. |
void |
handleSilentException(java.lang.Throwable e)
Mark this report as silent as send it.
|
java.lang.String |
putCustomData(java.lang.String key,
java.lang.String value)
Use this method to provide the ErrorReporter with data of your running
application.
|
java.lang.String |
removeCustomData(java.lang.String key)
Removes a key/value pair from your reports custom data field.
|
void |
setEnabled(boolean enabled)
Enable or disable this ErrorReporter.
|
void |
setExceptionHandlerInitializer(ExceptionHandlerInitializer initializer)
Deprecated.
since 4.8.0 use
ReportPrimer mechanism instead. |
void |
uncaughtException(java.lang.Thread t,
java.lang.Throwable e) |
@Deprecated public void addCustomData(@NonNull java.lang.String key, java.lang.String value)
putCustomData(String, String)
.key
- A key for your custom data.value
- The value associated to your key.public java.lang.String putCustomData(@NonNull java.lang.String key, java.lang.String value)
Use this method to provide the ErrorReporter with data of your running application. You should call this at several key places in your code the same way as you would output important debug data in a log file. Only the latest value is kept for each key (no history of the values is sent in the report).
key
- A key for your custom data.value
- The value associated to your key.removeCustomData(String)
,
getCustomData(String)
public void setExceptionHandlerInitializer(@Nullable ExceptionHandlerInitializer initializer)
ReportPrimer
mechanism instead.
Use this method to perform additional initialization before the
ErrorReporter handles a throwable. This can be used, for example, to put
custom data using putCustomData(String, String)
, which is not
available immediately after startup. It can be, for example, last 20
requests or something else. The call is thread safe.
ExceptionHandlerInitializer.initializeExceptionHandler(ErrorReporter)
will be executed on the main thread in case of uncaught exception and on
the caller thread of handleSilentException(Throwable)
or
handleException(Throwable)
.
Example. Add to the Application.onCreate()
:
ACRA.getErrorReporter().setExceptionHandlerInitializer(new ExceptionHandlerInitializer() {
@Override
public void initializeExceptionHandler(ErrorReporter reporter) {
reporter.putCustomData("CUSTOM_ACCUMULATED_DATA_TAG", someAccumulatedData.toString);
}
});
initializer
- The initializer. Can be null
.public java.lang.String removeCustomData(@NonNull java.lang.String key)
key
- The key of the data to be removed.putCustomData(String, String)
,
getCustomData(String)
public void clearCustomData()
public java.lang.String getCustomData(@NonNull java.lang.String key)
key
- The key of the data to be retrieved.putCustomData(String, String)
,
removeCustomData(String)
public void uncaughtException(@Nullable java.lang.Thread t, @NonNull java.lang.Throwable e)
uncaughtException
in interface java.lang.Thread.UncaughtExceptionHandler
public void handleSilentException(@Nullable java.lang.Throwable e)
e
- The Throwable
to be reported. If null the report will
contain a new Exception("Report requested by developer").public void setEnabled(boolean enabled)
enabled
- Whether this ErrorReporter should capture Exceptions and
forward them as crash reports.public void checkReportsOnApplicationStart()
ACRA.init(Application, ACRAConfiguration, boolean)
,
but the default is that it will.public void handleException(@Nullable java.lang.Throwable e, boolean endApplication)
Throwable
with the reporting interaction mode
configured by the developer.e
- The Throwable
to be reported. If null the report will
contain a new Exception("Report requested by developer").endApplication
- Set this to true if you want the application to be ended after
sending the report.public void handleException(@Nullable java.lang.Throwable e)
Throwable
with the reporting interaction mode
configured by the developer, the application is then killed and restarted
by the system.e
- The Throwable
to be reported. If null the report will
contain a new Exception("Report requested by developer").