diff --git a/sdk/src/main/java/com/bugsnag/android/ErrorStore.java b/sdk/src/main/java/com/bugsnag/android/ErrorStore.java index 7afc6a7ec3..950a526033 100644 --- a/sdk/src/main/java/com/bugsnag/android/ErrorStore.java +++ b/sdk/src/main/java/com/bugsnag/android/ErrorStore.java @@ -51,11 +51,10 @@ public int compare(File lhs, File rhs) { } void flushOnLaunch() { - final List crashReports = findLaunchCrashReports(); + List storedFiles = findStoredFiles(); + final List crashReports = findLaunchCrashReports(storedFiles); - if (crashReports.isEmpty() || config.getLaunchCrashThresholdMs() == 0) { - flushAsync(); // if disabled or no startup crash, flush async - } else { + if (!crashReports.isEmpty() && config.getLaunchCrashThresholdMs() != 0) { // Block the main thread for a 2 second interval as the app may crash very soon. // The request itself will run in a background thread and will continue after the 2 @@ -83,6 +82,9 @@ public void run() { } Logger.info("Continuing with Bugsnag initialisation"); } + + cancelQueuedFiles(storedFiles); // cancel all previously found files + flushAsync(); // flush any remaining errors async that weren't delivered } /** @@ -130,7 +132,7 @@ private void flushErrorReport(File errorFile) { } catch (DeliveryFailureException exception) { cancelQueuedFiles(Collections.singleton(errorFile)); Logger.warn("Could not send previously saved error(s)" - + " to Bugsnag, will try again later", exception); + + " to Bugsnag, will try again later", exception); } catch (Exception exception) { deleteStoredFiles(Collections.singleton(errorFile)); Logger.warn("Problem sending unsent error from disk", exception); @@ -141,8 +143,7 @@ boolean isLaunchCrashReport(File file) { return file.getName().endsWith("_startupcrash.json"); } - private List findLaunchCrashReports() { - Collection storedFiles = findStoredFiles(); + private List findLaunchCrashReports(Collection storedFiles) { List launchCrashes = new ArrayList<>(); for (File file : storedFiles) {