-
public final class BugsnagStatic access to a Bugsnag Client, the easiest way to use Bugsnag in your Android app. For example:
{@code * Bugsnag.start(this, "your-api-key"); * Bugsnag.notify(new RuntimeException("something broke!")); * }
-
-
Method Summary
Modifier and Type Method Description static ClientgetClient()Get the current Bugsnag Client instance. static Clientstart(@NonNull() Context androidContext)Initialize the static Bugsnag client static Clientstart(@NonNull() Context androidContext, @NonNull() String apiKey)Initialize the static Bugsnag client static Clientstart(@NonNull() Context androidContext, @NonNull() Configuration config)Initialize the static Bugsnag client static booleanisStarted()Returns true if one of the startmethods have been has been called andso Bugsnag is initialized; false ifstarthas not been called and theother methods will throw{@code IllegalStateException}.static StringgetContext()Bugsnag uses the concept of "contexts" to help display and group your errors. static voidsetContext(@Nullable() String context)Bugsnag uses the concept of "contexts" to help display and group your errors. static StringsetGroupingDiscriminator(@Nullable() String groupingDiscriminator)Set the Grouping Discriminator and return its previous value (if any was set). static StringgetGroupingDiscriminator()static voidsetUser(@Nullable() String id, @Nullable() String email, @Nullable() String name)Sets the user associated with the event. static UsergetUser()Returns the currently set User information. static voidaddOnError(@NonNull() OnErrorCallback onError)Add a "on error" callback, to execute code at the point where an error report iscaptured in Bugsnag. static voidremoveOnError(@NonNull() OnErrorCallback onError)Removes a previously added "on error" callback static voidaddOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)Add an "on breadcrumb" callback, to execute code before everybreadcrumb captured by Bugsnag. static voidremoveOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)Removes a previously added "on breadcrumb" callback static voidaddOnSession(@NonNull() OnSessionCallback onSession)Add an "on session" callback, to execute code before everysession captured by Bugsnag. static voidremoveOnSession(@NonNull() OnSessionCallback onSession)Removes a previously added "on session" callback static voidnotify(@NonNull() Throwable exception)Notify Bugsnag of a handled exception static voidnotify(@NonNull() Throwable exception, @Nullable() OnErrorCallback onError)Notify Bugsnag of a handled exception static voidnotify(@NonNull() Throwable exception, @Nullable() ErrorOptions options, @Nullable() OnErrorCallback onError)Notify Bugsnag of a handled exception static voidaddMetadata(@NonNull() String section, @NonNull() Map<String, out Object> value)Adds a map of multiple metadata key-value pairs to the specified section. static voidaddMetadata(@NonNull() String section, @NonNull() String key, @Nullable() Object value)Adds the specified key and value in the specified section. static voidclearMetadata(@NonNull() String section)Removes all the data from the specified section. static voidclearMetadata(@NonNull() String section, @NonNull() String key)Removes data with the specified key from the specified section. static Map<String, Object>getMetadata(@NonNull() String section)Returns a map of data in the specified section. static ObjectgetMetadata(@NonNull() String section, @NonNull() String key)Returns the value of the specified key in the specified section. static voidleaveBreadcrumb(@NonNull() String message)Leave a "breadcrumb" log message, representing an action that occurredin your app, to aid with debugging. static 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 static voidstartSession()Starts tracking a new session. static 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. static voidpauseSession()Pauses tracking of a session. static List<Breadcrumb>getBreadcrumbs()Returns the current buffer of breadcrumbs that will be sent with captured events. static LastRunInfogetLastRunInfo()Retrieves information about the last launch of the application, if it has been run before. static voidmarkLaunchCompleted()Informs Bugsnag that the application has finished launching. static voidaddFeatureFlag(@NonNull() String name)Add a single feature flag with no variant. static voidaddFeatureFlag(@NonNull() String name, @Nullable() String variant)Add a single feature flag with an optional variant. static voidaddFeatureFlags(@NonNull() Iterable<FeatureFlag> featureFlags)Add a collection of feature flags. static voidclearFeatureFlag(@NonNull() String name)Remove a single feature flag regardless of its current status. static voidclearFeatureFlags()Clear all of the feature flags. static voidsetOutOfMemoryHandler(@Nullable() OutOfMemoryHandler handler)Override or intercept the default error handling for OutOfMemoryErrors. static OutOfMemoryHandlergetOutOfMemoryHandler()Return the currently defined OutOfMemoryHandler if one is being used. -
-
Method Detail
-
start
@NonNull() static Client start(@NonNull() Context androidContext)
Initialize the static Bugsnag client
- Parameters:
androidContext- an Android context, usuallythis
-
start
@NonNull() static Client start(@NonNull() Context androidContext, @NonNull() String apiKey)
Initialize the static Bugsnag client
- Parameters:
androidContext- an Android context, usuallythisapiKey- your Bugsnag API key from your Bugsnag dashboard
-
start
@NonNull() static Client start(@NonNull() Context androidContext, @NonNull() Configuration config)
Initialize the static Bugsnag client
- Parameters:
androidContext- an Android context, usuallythisconfig- a configuration for the Client
-
isStarted
static boolean isStarted()
Returns true if one of the
startmethods have been has been called andso Bugsnag is initialized; false ifstarthas not been called and theother methods will throw{@code IllegalStateException}.
-
getContext
@Nullable() static 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
static 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() static String setGroupingDiscriminator(@Nullable() String groupingDiscriminator)
Set the Grouping Discriminator and return its previous value (if any was set).
- Parameters:
groupingDiscriminator- the new grouping discriminator or null to clear it
-
getGroupingDiscriminator
@Nullable() static String getGroupingDiscriminator()
-
setUser
static void setUser(@Nullable() String id, @Nullable() String email, @Nullable() String name)
Sets the user associated with the event.
-
addOnError
static 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:
{@code * Bugsnag.addOnError((Event event) -> { * event.setSeverity(Severity.INFO); * return true; * }); * }- Parameters:
onError- a callback to run before sending errors to Bugsnag
-
removeOnError
static void removeOnError(@NonNull() OnErrorCallback onError)
Removes a previously added "on error" callback
- Parameters:
onError- the callback to remove
-
addOnBreadcrumb
static 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:
{@code * Bugsnag.onBreadcrumb((Breadcrumb breadcrumb) -> { * return false; // ignore the breadcrumb * }); * }- Parameters:
onBreadcrumb- a callback to run before a breadcrumb is captured
-
removeOnBreadcrumb
static void removeOnBreadcrumb(@NonNull() OnBreadcrumbCallback onBreadcrumb)
Removes a previously added "on breadcrumb" callback
- Parameters:
onBreadcrumb- the callback to remove
-
addOnSession
static 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:
{@code * Bugsnag.onSession((Session session) -> { * return false; // ignore the session * }); * }- Parameters:
onSession- a callback to run before a session is captured
-
removeOnSession
static void removeOnSession(@NonNull() OnSessionCallback onSession)
Removes a previously added "on session" callback
- Parameters:
onSession- the callback to remove
-
notify
static void notify(@NonNull() Throwable exception)
Notify Bugsnag of a handled exception
- Parameters:
exception- the exception to send to Bugsnag
-
notify
static void notify(@NonNull() Throwable exception, @Nullable() OnErrorCallback onError)
Notify Bugsnag of a handled exception
- Parameters:
exception- the exception to send to BugsnagonError- callback invoked on the generated error report foradditional modification
-
notify
static void notify(@NonNull() Throwable exception, @Nullable() ErrorOptions options, @Nullable() OnErrorCallback onError)
Notify Bugsnag of a handled exception
- Parameters:
exception- the exception to send to Bugsnagoptions- additional options to adjust the reporting of the exceptiononError- callback invoked on the generated error report foradditional modification
-
addMetadata
static 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
static 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
static void clearMetadata(@NonNull() String section)
Removes all the data from the specified section.
-
clearMetadata
static void clearMetadata(@NonNull() String section, @NonNull() String key)
Removes data with the specified key from the specified section.
-
getMetadata
@Nullable() static Map<String, Object> getMetadata(@NonNull() String section)
Returns a map of data in the specified section.
-
getMetadata
@Nullable() static Object getMetadata(@NonNull() String section, @NonNull() String key)
Returns the value of the specified key in the specified section.
-
leaveBreadcrumb
static 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
static 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
-
startSession
static 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.
-
resumeSession
static 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.
-
pauseSession
static 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.
-
getBreadcrumbs
@NonNull() static 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.
-
getLastRunInfo
@Nullable() static 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.
-
markLaunchCompleted
static 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.
-
addFeatureFlag
static void addFeatureFlag(@NonNull() String name)
Add a single feature flag with no variant. If there is an existing feature flag with thesame name, it will be overwritten to have no variant.
- Parameters:
name- the name of the feature flag to add
-
addFeatureFlag
static void addFeatureFlag(@NonNull() String name, @Nullable() String variant)
Add a single feature flag with an optional variant. If there is an existing featureflag with the same name, it will be overwritten with the new variant. If the variant is
{@code null}this method has the same behaviour as addFeatureFlag.- Parameters:
name- the name of the feature flag to addvariant- the variant to set the feature flag to, or{@code null}to specify a featureflag with no variant
-
addFeatureFlags
static void addFeatureFlags(@NonNull() Iterable<FeatureFlag> featureFlags)
Add a collection of feature flags. This method behaves exactly the same as calling addFeatureFlag for each of the
{@code FeatureFlag}objects.- Parameters:
featureFlags- the feature flags to add
-
clearFeatureFlag
static void clearFeatureFlag(@NonNull() String name)
Remove a single feature flag regardless of its current status. This will stop the specifiedfeature flag from being reported. If the named feature flag does not exist this willhave no effect.
- Parameters:
name- the name of the feature flag to remove
-
clearFeatureFlags
static void clearFeatureFlags()
Clear all of the feature flags. This will stop all feature flags from being reported.
-
setOutOfMemoryHandler
static 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() static OutOfMemoryHandler getOutOfMemoryHandler()
Return the currently defined OutOfMemoryHandler if one is being used.
-
-
-
-