Skip to content

Detect app crashed last launch #911

Closed

Description

@chreck

Platform:

  • Android
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    minSdkVersion 21
    targetSdkVersion 29

  • Java
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

  • Kotlin

  • NDK

IDE:

  • Android Studio 3.5.3

Build system:

  • Gradle 5.4.1

Android Gradle Plugin:

  • Yes 3.5.3

Sentry Android Gradle Plugin:

  • Yes 1.7.31

Proguard/R8:

  • Enabled
  • Disabled

sentry-android installed with:

  • JCenter

The version of sentry-android:
2.0.0


I have the following question:

If I have a crash in my mobile app which is happening during the startup, I do not get them in sentry. So my question is "How can I transmit the previous crash"?

On iOS there is a possibility to detect if a previous crash happened or not. It is
[SentryClient.sharedClient crashedLastLaunch] . On the iOS side of my mobile app I implemented manually

  1. Init Sentry
  2. detect if a crash was happening
  3. wait 2 seconds (hope that the crash is transmitted)
  4. initialise the app

Is there a similar possibility on the Android side, how can I see the open transmissions to sentry backend?

Activity

  1. marandaneto commented on Mar 13, 2020

    @marandaneto
    Contributor

    hey @chreck thanks for your message.

    We intend to solve that when we implement the flush method of the unified API which is not done yet.
    See: https://github.com/getsentry/sentry-android/blob/master/sentry-core/src/main/java/io/sentry/core/SentryClient.java#L222

    On App restart, there's an Integration that is gonna send all the cached crashes right away, but if the App. crashes right after initing the Sentry Android SDK, that could be not long enough, true, with the flush method you would be able to do a synchronous call on App. init and wait for a time period.

  2. marandaneto commented on Apr 8, 2020

    @marandaneto
    Contributor

    hey @chreck while we don't have an API for that, there's a workaround which looks like this:

    SentryAndroid.init(this);
    File cacheDir = new File(getApplicationContext().getCacheDir(), "sentry");
    // if you use NDK, you may check the outbox folder too, "getApplicationContext().getCacheDir()/sentry/outbox"
    if (cacheDir.exists()) {
        File[] files = cacheDir.listFiles();
        if (files != null && files.length > 0) {
            Thread.sleep(2000);
        }
    }
    

    as all files are being read, sent and deleted, once it's empty, it means all of them were flushed out to Sentry.

    I hope that helps you out, for now, stay tuned, thanks.

  3. bruno-garcia commented on Sep 11, 2020

    @bruno-garcia
    Member

    We added an API on cocoa, would make it sense to add here too with the same name.
    Add to unified API docs

  4. marandaneto commented on Apr 15, 2021

    @marandaneto
    Contributor

    dup of #1125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions