Package 

Class Client

  • 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, FeatureFlagAware
                        

    A 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!"));
    • Constructor Detail

      • Client

        Client(Context androidContext)
        Initialize a Bugsnag client
        Parameters:
        androidContext - an Android context, usually this
      • Client

        Client(Context androidContext, String apiKey)
        Initialize a Bugsnag client
        Parameters:
        androidContext - an Android context, usually this
        apiKey - your Bugsnag API key from your Bugsnag dashboard
      • Client

        Client(Context androidContext, Configuration configuration)
        Initialize a Bugsnag client
        Parameters:
        androidContext - an Android context, usually this
        configuration - 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)
      • 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 returnfalse from 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
      • 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 false from 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
      • 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 false from 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
      • 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 Bugsnag
        onError - callback invoked on the generated error report foradditional modification
      • 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.

      • 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 label
        metadata - Additional diagnostic information about the app environment
        type - A category for the breadcrumb
      • 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.