-
- All Implemented Interfaces:
-
com.bugsnag.android.CallbackAware,com.bugsnag.android.FeatureFlagAware,com.bugsnag.android.MetadataAware,com.bugsnag.android.UserAware
public class Client implements MetadataAware, CallbackAware, UserAware, FeatureFlagAwareA Bugsnag Client instance allows you to use Bugsnag in your Android app. Typically you'd instead use the static access provided in the Bugsnag class.
Example usage: Client client = new Client(this, "your-api-key"); client.notify(new RuntimeException("something broke!"));
-
-
Field Summary
Fields Modifier and Type Field Description final LastRunInfolastRunInfo
-
Method Summary
Modifier and Type Method Description LastRunInfogetLastRunInfo()Retrieves information about the last launch of the application, if it has been run before.For example, this allows checking whether the app crashed on its last launch, which couldbe used to perform conditional behaviour to recover from crashes, such as clearing theapp data cache. voidstartSession()Starts tracking a new session. voidpauseSession()Pauses tracking of a session. booleanresumeSession()Resumes a session which has previously been paused, or starts a new session if none exists.If a session has already been resumed or started and has not been paused, calling thismethod will have no effect. StringgetContext()Bugsnag uses the concept of "contexts" to help display and group your errors. voidsetContext(@Nullable() String context)Bugsnag uses the concept of "contexts" to help display and group your errors. StringsetGroupingDiscriminator(@Nullable() String groupingDiscriminator)Sets a new error grouping discriminator, and returns the previous value. StringgetGroupingDiscriminator()Returns the current global error grouping discriminator, or null if none is set. voidsetUser(@Nullable() String id, @Nullable() String email, @Nullable() String name)Sets the user associated with the event. UsergetUser()Returns the currently set User information. voidaddOnError(@NonNull() OnErrorCallback onError)Add a "on error" callback, to execute code at the point where an error report iscaptured in Bugsnag.You can use this to add or modify information attached to an Eventbefore it is sent to your dashboard. voidremoveOnError(@NonNull() OnErrorCallback onError)Removes a previously added "on error" callback voidaddOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)Add an "on breadcrumb" callback, to execute code before everybreadcrumb captured by Bugsnag.You can use this to modify breadcrumbs before they are stored by Bugsnag. voidremoveOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)Removes a previously added "on breadcrumb" callback voidaddOnSession(@NonNull() OnSessionCallback onSession)Add an "on session" callback, to execute code before everysession captured by Bugsnag.You can use this to modify sessions before they are stored by Bugsnag. voidremoveOnSession(@NonNull() OnSessionCallback onSession)Removes a previously added "on session" callback voidnotify(@NonNull() Throwable exception)Notify Bugsnag of a handled exception voidnotify(@NonNull() Throwable exc, @Nullable() OnErrorCallback onError)Notify Bugsnag of a handled exception voidnotify(@NonNull() Throwable exc, @Nullable() ErrorOptions options, @Nullable() OnErrorCallback onError)Notify Bugsnag of a handled exception voidsetOutOfMemoryHandler(@Nullable() OutOfMemoryHandler handler)Override or intercept the default error handling for OutOfMemoryErrors. OutOfMemoryHandlergetOutOfMemoryHandler()Return the currently defined OutOfMemoryHandler if one is being used. List<Breadcrumb>getBreadcrumbs()Returns the current buffer of breadcrumbs that will be sent with captured events. voidaddMetadata(@NonNull() String section, @NonNull() Map<String, out Object> value)Adds a map of multiple metadata key-value pairs to the specified section. voidaddMetadata(@NonNull() String section, @NonNull() String key, @Nullable() Object value)Adds the specified key and value in the specified section. voidclearMetadata(@NonNull() String section)Removes all the data from the specified section. voidclearMetadata(@NonNull() String section, @NonNull() String key)Removes data with the specified key from the specified section. Map<String, Object>getMetadata(@NonNull() String section)Returns a map of data in the specified section. ObjectgetMetadata(@NonNull() String section, @NonNull() String key)Returns the value of the specified key in the specified section. voidleaveBreadcrumb(@NonNull() String message)Leave a "breadcrumb" log message, representing an action that occurredin your app, to aid with debugging. voidleaveBreadcrumb(@NonNull() String message, @Nullable() Map<String, Object> metadata, @NonNull() BreadcrumbType type)Leave a "breadcrumb" log message representing an action or event whichoccurred in your app, to aid with debugging voidaddFeatureFlag(@NonNull() String name)voidaddFeatureFlag(@NonNull() String name, @Nullable() String variant)voidaddFeatureFlags(@NonNull() Iterable<FeatureFlag> featureFlags)voidclearFeatureFlag(@NonNull() String name)voidclearFeatureFlags()voidmarkLaunchCompleted()Informs Bugsnag that the application has finished launching. -
Methods inherited from class com.bugsnag.android.MetadataAware
addMetadata, clearMetadata, getMetadata -
Methods inherited from class com.bugsnag.android.CallbackAware
addOnBreadcrumb, addOnError, addOnSession, removeOnBreadcrumb, removeOnError, removeOnSession -
Methods inherited from class com.bugsnag.android.UserAware
getUser, setUser -
Methods inherited from class com.bugsnag.android.FeatureFlagAware
addFeatureFlag, addFeatureFlags, clearFeatureFlag, clearFeatureFlags -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
Client
Client(Context androidContext)
Initialize a Bugsnag client- Parameters:
androidContext- an Android context, usuallythis
-
Client
Client(Context androidContext, String apiKey)
Initialize a Bugsnag client- Parameters:
androidContext- an Android context, usuallythisapiKey- your Bugsnag API key from your Bugsnag dashboard
-
Client
Client(Context androidContext, Configuration configuration)
Initialize a Bugsnag client- Parameters:
androidContext- an Android context, usuallythisconfiguration- a configuration for the Client
-
-
Method Detail
-
getLastRunInfo
@Nullable() LastRunInfo getLastRunInfo()
Retrieves information about the last launch of the application, if it has been run before.For example, this allows checking whether the app crashed on its last launch, which couldbe used to perform conditional behaviour to recover from crashes, such as clearing theapp data cache.
-
startSession
void startSession()
Starts tracking a new session. You should disable automatic session tracking via setAutoTrackSessions if you call this method.
You should call this at the appropriate time in your application when you wish to start asession. Any subsequent errors which occur in your application will still be reported toBugsnag but will not count towards your application'sstability score. This will start a new session even if there is already an existingsession; you should call resumeSession if you only want to start a sessionwhen one doesn't already exist.
-
pauseSession
void pauseSession()
Pauses tracking of a session. You should disable automatic session tracking via setAutoTrackSessions if you call this method.
You should call this at the appropriate time in your application when you wish to pause asession. Any subsequent errors which occur in your application will still be reported toBugsnag but will not count towards your application'sstability score. This can be advantageous if, for example, you do not wish thestability score to include crashes in a background service.
-
resumeSession
boolean resumeSession()
Resumes a session which has previously been paused, or starts a new session if none exists.If a session has already been resumed or started and has not been paused, calling thismethod will have no effect. You should disable automatic session tracking via setAutoTrackSessions if you call this method.
It's important to note that sessions are stored in memory for the lifetime of theapplication process and are not persisted on disk. Therefore calling this method on appstartup would start a new session, rather than continuing any previous session.You should call this at the appropriate time in your application when you wish to resumea previously started session. Any subsequent errors which occur in your application willstill be reported to Bugsnag but will not count towards your application'sstability score.
-
getContext
@Nullable() String getContext()
Bugsnag uses the concept of "contexts" to help display and group your errors. Contextsrepresent what was happening in your application at the time an error occurs.In an android app the "context" is automatically set as the foreground Activity.If you would like to set this value manually, you should alter this property.
-
setContext
void setContext(@Nullable() String context)
Bugsnag uses the concept of "contexts" to help display and group your errors. Contextsrepresent what was happening in your application at the time an error occurs.In an android app the "context" is automatically set as the foreground Activity.If you would like to set this value manually, you should alter this property.
-
setGroupingDiscriminator
@Nullable() String setGroupingDiscriminator(@Nullable() String groupingDiscriminator)
Sets a new error grouping discriminator, and returns the previous value. Similar tocontexts, grouping discriminators are used to group errors in your Bugsnag dashboard.By default, errors are grouped by their stacktrace. By setting a grouping discriminatorerrors that would normally be grouped separately will be grouped together if theyhave the same grouping discriminator.
- Parameters:
groupingDiscriminator- the new grouping discriminator (or null to clear any)
-
getGroupingDiscriminator
@Nullable() String getGroupingDiscriminator()
Returns the current global error grouping discriminator, or null if none is set.
-
setUser
void setUser(@Nullable() String id, @Nullable() String email, @Nullable() String name)
Sets the user associated with the event.
-
addOnError
void addOnError(@NonNull() OnErrorCallback onError)
Add a "on error" callback, to execute code at the point where an error report iscaptured in Bugsnag.You can use this to add or modify information attached to an Eventbefore it is sent to your dashboard. You can also return
falsefrom any callback to prevent delivery. "on error"callbacks do not run before reports generated in the eventof immediate app termination from crashes in C/C++ code.For example:Bugsnag.addOnError(new OnErrorCallback() {public boolean run(Event event) {event.setSeverity(Severity.INFO);return true; } })- Parameters:
onError- a callback to run before sending errors to Bugsnag
-
removeOnError
void removeOnError(@NonNull() OnErrorCallback onError)
Removes a previously added "on error" callback
- Parameters:
onError- the callback to remove
-
addOnBreadcrumb
void addOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)
Add an "on breadcrumb" callback, to execute code before everybreadcrumb captured by Bugsnag.You can use this to modify breadcrumbs before they are stored by Bugsnag.You can also return
falsefrom any callback to ignore a breadcrumb.For example:Bugsnag.onBreadcrumb(new OnBreadcrumbCallback() {public boolean run(Breadcrumb breadcrumb) {return false; // ignore the breadcrumb } })- Parameters:
onBreadcrumb- a callback to run before a breadcrumb is captured
-
removeOnBreadcrumb
void removeOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)
Removes a previously added "on breadcrumb" callback
- Parameters:
onBreadcrumb- the callback to remove
-
addOnSession
void addOnSession(@NonNull() OnSessionCallback onSession)
Add an "on session" callback, to execute code before everysession captured by Bugsnag.You can use this to modify sessions before they are stored by Bugsnag.You can also return
falsefrom any callback to ignore a session.For example:Bugsnag.onSession(new OnSessionCallback() {public boolean run(Session session) {return false; // ignore the session } })- Parameters:
onSession- a callback to run before a session is captured
-
removeOnSession
void removeOnSession(@NonNull() OnSessionCallback onSession)
Removes a previously added "on session" callback
- Parameters:
onSession- the callback to remove
-
notify
void notify(@NonNull() Throwable exception)
Notify Bugsnag of a handled exception
- Parameters:
exception- the exception to send to Bugsnag
-
notify
void notify(@NonNull() Throwable exc, @Nullable() OnErrorCallback onError)
Notify Bugsnag of a handled exception
- Parameters:
exc- the exception to send to BugsnagonError- callback invoked on the generated error report foradditional modification
-
notify
void notify(@NonNull() Throwable exc, @Nullable() ErrorOptions options, @Nullable() OnErrorCallback onError)
Notify Bugsnag of a handled exception
- Parameters:
exc- the exception to send to Bugsnagoptions- the error optionsonError- callback invoked on the generated error report foradditional modification
-
setOutOfMemoryHandler
void setOutOfMemoryHandler(@Nullable() OutOfMemoryHandler handler)
Override or intercept the default error handling for OutOfMemoryErrors.
- Parameters:
handler- the new handler to use (or null to revert to normal error handling for OOMs)
-
getOutOfMemoryHandler
@Nullable() OutOfMemoryHandler getOutOfMemoryHandler()
Return the currently defined OutOfMemoryHandler if one is being used.
-
getBreadcrumbs
@NonNull() List<Breadcrumb> getBreadcrumbs()
Returns the current buffer of breadcrumbs that will be sent with captured events. Thisordered list represents the most recent breadcrumbs to be captured up to the limitset in getMaxBreadcrumbs.The returned collection is readonly and mutating the list will cause no effect on theClient's state. If you wish to alter the breadcrumbs collected by the Client then you shoulduse setEnabledBreadcrumbTypes and addOnBreadcrumb instead.
-
addMetadata
void addMetadata(@NonNull() String section, @NonNull() Map<String, out Object> value)
Adds a map of multiple metadata key-value pairs to the specified section.
-
addMetadata
void addMetadata(@NonNull() String section, @NonNull() String key, @Nullable() Object value)
Adds the specified key and value in the specified section. The value can be ofany primitive type or a collection such as a map, set or array.
-
clearMetadata
void clearMetadata(@NonNull() String section)
Removes all the data from the specified section.
-
clearMetadata
void clearMetadata(@NonNull() String section, @NonNull() String key)
Removes data with the specified key from the specified section.
-
getMetadata
@Nullable() Map<String, Object> getMetadata(@NonNull() String section)
Returns a map of data in the specified section.
-
getMetadata
@Nullable() Object getMetadata(@NonNull() String section, @NonNull() String key)
Returns the value of the specified key in the specified section.
-
leaveBreadcrumb
void leaveBreadcrumb(@NonNull() String message)
Leave a "breadcrumb" log message, representing an action that occurredin your app, to aid with debugging.
- Parameters:
message- the log message to leave
-
leaveBreadcrumb
void leaveBreadcrumb(@NonNull() String message, @Nullable() Map<String, Object> metadata, @NonNull() BreadcrumbType type)
Leave a "breadcrumb" log message representing an action or event whichoccurred in your app, to aid with debugging
- Parameters:
message- A short labelmetadata- Additional diagnostic information about the app environmenttype- A category for the breadcrumb
-
addFeatureFlag
void addFeatureFlag(@NonNull() String name)
-
addFeatureFlag
void addFeatureFlag(@NonNull() String name, @Nullable() String variant)
-
addFeatureFlags
void addFeatureFlags(@NonNull() Iterable<FeatureFlag> featureFlags)
-
clearFeatureFlag
void clearFeatureFlag(@NonNull() String name)
-
clearFeatureFlags
void clearFeatureFlags()
-
markLaunchCompleted
void markLaunchCompleted()
Informs Bugsnag that the application has finished launching. Once this has been called isLaunching will always be false in any new error reports,and synchronous delivery will not be attempted on the next launch for any fatal crashes.By default this method will be called after Bugsnag is initialized when getLaunchDurationMillis has elapsed. Invoking this method manuallyhas precedence over the value supplied via the launchDurationMillis configuration option.
-
-
-
-