Identifying crashes at launch

If your app crashes whilst it is launching, you may want to give the crash more attention. BugSnag provides an API to mark events that occur during startup and also allows you to detect recurrent launch crashes.

Controlling the launch period

By default, BugSnag will treat crashes that occur during the first 5 seconds after calling Bugsnag.start() as having occurred during launch.

Events that occur during the app launch have their app.isLaunching property set to true.

You can modify the launch time period using the launchDurationMillis configuration option.

Configuration config = Configuration.load(this);
config.setLaunchDurationMillis(2000);
Bugsnag.start(this, config);
val config = Configuration.load(this)
config.launchDurationMillis = 2000
Bugsnag.start(this, config)

You can also indicate that your app has finished launching by calling Bugsnag.markLaunchCompleted().

Bugsnag.markLaunchCompleted();
Bugsnag.markLaunchCompleted()

You can disable the automatic ending of the launch period by setting launchDurationMillis to 0 - in this case the app will be considered to be launching until Bugsnag.markLaunchCompleted() is called.

Configuration config = Configuration.load(this);
config.setLaunchDurationMillis(0);
Bugsnag.start(this, config);

// Once your app has finished launching
Bugsnag.markLaunchCompleted();
val config = Configuration.load(this)
config.launchDurationMillis = 0
Bugsnag.start(this, config)

// Once your app has finished launching
Bugsnag.markLaunchCompleted()

Sending launch crashes

If the previous run of your app crashed during app launch, Bugsnag.start() will block the calling thread for up to 2 seconds to allow the crash report to be sent before the app continues launching. In cases where a launch crash is persistent, this improves the reliability of crash reporting.

This behaviour can be disabled using the sendLaunchCrashesSynchronously option.

Configuration config = Configuration.load(this);
// To prevent sending launch crashes synchronously
config.setSendLaunchCrashesSynchronously(false);
Bugsnag.start(this, config);
val config = Configuration.load(this)
// To prevent sending launch crashes synchronously
config.sendLaunchCrashesSynchronously = false
Bugsnag.start(this, config)

Recovering after launch crashes

After a launch crash, it may be appropriate to take some actions in your app, such as removing cached data or resetting some persistent state, to make another one less likely to occur.

Bugsnag.start();
LastRunInfo lastRunInfo = Bugsnag.getLastRunInfo();
if (lastRunInfo != null && lastRunInfo.getCrashedDuringLaunch()) {
    // Enable "safe mode"
}
Bugsnag.start()

if (Bugsnag.getLastRunInfo()?.crashedDuringLaunch == true) {
    // Enable "safe mode"
}

The lastRunInfo object contains the following properties:

property type description
consecutiveLaunchCrashes Integer The number of consecutive runs that have ended with a crash while launching.
crashed Boolean true if the previous run crashed.
crashedDuringLaunch Boolean true if the previous run crashed while launching.