public class ErrorReporter extends Object implements 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 | Class and Description |
---|---|
class |
ErrorReporter.ReportBuilder
Fluent API used to assemble the different options used for a crash report
|
Modifier and Type | Method and Description |
---|---|
void |
addCustomData(String key,
String value)
Deprecated.
|
void |
addReportSender(ReportSender sender)
Add a
ReportSender to the list of active ReportSender s. |
void |
checkReportsOnApplicationStart()
This method looks for pending reports and does the action required
depending on the interaction mode set.
|
void |
clearCustomData()
Removes all key/value pairs from your reports custom data field.
|
String |
getCustomData(String key)
Gets the current value for a key in your reports custom data field.
|
static ErrorReporter |
getInstance()
Deprecated.
since 4.3.0 Use
ACRA.getErrorReporter()
instead. |
void |
handleException(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(Throwable e,
boolean endApplication)
Send a report for a
Throwable with the reporting interaction mode
configured by the developer. |
void |
handleSilentException(Throwable e)
Send a report for this
Throwable silently (forces the use of
ReportingInteractionMode.SILENT for this report, whatever is the
mode set for the application. |
String |
putCustomData(String key,
String value)
Use this method to provide the ErrorReporter with data of your running
application.
|
void |
removeAllReportSenders()
Clears the list of active
ReportSender s. |
String |
removeCustomData(String key)
Removes a key/value pair from your reports custom data field.
|
void |
removeReportSender(ReportSender sender)
Remove a specific instance of
ReportSender from the list of
active ReportSender s. |
void |
removeReportSenders(Class<?> senderClass)
Remove all
ReportSender instances from a specific class. |
ErrorReporter.ReportBuilder |
reportBuilder()
Creates a new crash report builder
|
void |
setDefaultReportSenders()
Sets relevant ReportSenders to the ErrorReporter, replacing any
previously set ReportSender.
|
void |
setEnabled(boolean enabled)
Enable or disable this ErrorReporter.
|
void |
setExceptionHandlerInitializer(ExceptionHandlerInitializer initializer)
Use this method to perform additional initialization before the
ErrorReporter handles a throwable.
|
void |
setReportSender(ReportSender sender)
Removes all previously set
ReportSender s and set the given one as
the new ReportSender . |
void |
uncaughtException(Thread t,
Throwable e) |
@Deprecated public static ErrorReporter getInstance()
ACRA.getErrorReporter()
instead.IllegalStateException
- if ACRA.init(android.app.Application)
has not yet
been called.@Deprecated public void addCustomData(String key, String value)
putCustomData(String, String)
.key
- A key for your custom data.value
- The value associated to your key.public String putCustomData(String key, 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).
The key/value pairs will be stored in the GoogleDoc spreadsheet in the "custom" column, as a text containing a 'key = value' pair on each line.
key
- A key for your custom data.value
- The value associated to your key.removeCustomData(String)
,
getCustomData(String)
public void setExceptionHandlerInitializer(ExceptionHandlerInitializer initializer)
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 String removeCustomData(String key)
key
- The key of the data to be removed.putCustomData(String, String)
,
getCustomData(String)
public void clearCustomData()
public String getCustomData(String key)
key
- The key of the data to be retrieved.putCustomData(String, String)
,
removeCustomData(String)
public void addReportSender(ReportSender sender)
ReportSender
to the list of active ReportSender
s.sender
- The ReportSender
to be added.public void removeReportSender(ReportSender sender)
ReportSender
from the list of
active ReportSender
s.sender
- The ReportSender
instance to be removed.public void removeReportSenders(Class<?> senderClass)
ReportSender
instances from a specific class.senderClass
- ReportSender class whose instances should be removed.public void removeAllReportSenders()
ReportSender
s. You should then call
addReportSender(ReportSender)
or ACRA will not send any report
anymore.public void setReportSender(ReportSender sender)
ReportSender
s and set the given one as
the new ReportSender
.sender
- ReportSender to set as the sole sender for this ErrorReporter.public void uncaughtException(Thread t, Throwable e)
uncaughtException
in interface Thread.UncaughtExceptionHandler
public void handleSilentException(Throwable e)
Throwable
silently (forces the use of
ReportingInteractionMode.SILENT
for this report, whatever is the
mode set for the application. Very useful for tracking difficult defects.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()
public void handleException(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(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").public ErrorReporter.ReportBuilder reportBuilder()
ReportBuilder
public void setDefaultReportSenders()
Copyright © 2010-2015. All Rights Reserved.