7

How to show a Dialog after crash by using Crashlytics.

for example: after crash I need open a dialog where user will put any comment(note) how he did that crash.

Is any option in Crashlytics?

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138

1 Answers1

14

Yes, definitely. It's also extremely easy.

Crashlytics.getInstance().setListener(new CrashlyticsListener() {
  @Override
  public void crashlyticsDidDetectCrashDuringPreviousExecution() {
    // now it's the right time to show the dialog
  }
});
Crashlytics.start(context);

EDIT (Deprecated as of July 2015)

If you're using the new Fabric integration, the code is slightly different (as seen here). It should look like this:

Fabric.with(this, new Crashlytics());
Crashlytics.getInstance().setListener(new CrashlyticsListener() {
  @Override
  public void crashlyticsDidDetectCrashDuringPreviousExecution() {
    // now it's the right time to show the dialog
  }
});

EDIT 2 (The latest Fabric SDKs have deprecated the setMethods)

final CrashlyticsListener listener = new CrashlyticsListener() {
            @Override
            public void crashlyticsDidDetectCrashDuringPreviousExecution(){
                  // now it's the right time to show the dialog
            }
        };

final CrashlyticsCore core = new CrashlyticsCore
                                  .Builder()
                                  .listener(listener)
                                  .build();

Fabric.with(this, new Crashlytics.Builder().core(core).build());

To test your integration, you can simply call Crashlytics.getInstance().crash(). Simple but handy.

Community
  • 1
  • 1
Sebastiano
  • 12,289
  • 6
  • 47
  • 80
  • Where should I add it? In Application class? – NickUnuchek Feb 04 '15 at 11:10
  • No any method Crashlytics.start(this); – NickUnuchek Feb 04 '15 at 11:28
  • You need to pass a `Context` to the `start()` method. – Sebastiano Feb 04 '15 at 11:29
  • Crashlytics haven't method start(); – NickUnuchek Feb 04 '15 at 11:30
  • Yes, it does. It is the only way of initializing the SDK. There are two, in fact: `start(Context context)` and `start(Context context, float delay)`. If you don't see them, then you have some issues in using the Crashlytics plugin. – Sebastiano Feb 04 '15 at 11:33
  • previously I add this by this tutorial – NickUnuchek Feb 04 '15 at 11:38
  • plugin version 2.1.0 doesn't have method Crashlytics.start(Context context); – NickUnuchek Feb 04 '15 at 11:48
  • I am running the 2.4.0 version, but 2.1.0 have it as well. What other methods do you see? – Sebastiano Feb 04 '15 at 11:51
  • See on this png https://docs.google.com/file/d/0Bzg--_QQ214sVHZOVHpYenptZWc/edit?usp=drivesdk – NickUnuchek Feb 04 '15 at 13:14
  • Oh, I see now. You're using the Fabric-integrated version of Crashlytics. I've updated my answer accordingly. – Sebastiano Feb 04 '15 at 13:49
  • Does this occur right when the crash occurs? The name of the functions suggests it doesn't. Is there a way to have a callback for when the crash occurs? I'd like to add some information about the crash and device right when the crash occurs (available heap-memory, activity stack,...) . – android developer May 16 '16 at 14:27
  • 1
    @androiddeveloper Crashlytics sends the crashes on the next startup. You can use custom logging/keys with crashlytics. They will be visible together with the stacktrace. https://docs.fabric.io/android/crashlytics/enhanced-reports.html?#custom-logging – Fhl Jun 02 '16 at 09:23
  • Interesting. How do you know this? What happens if there is a crash and the user has uninstalled the app because of this? Why can't they send the crash information right away (using maybe a second OS-process) ? – android developer Jun 02 '16 at 13:14
  • Is this listener called before or after the crash? Can I provide some runtime monitoring data when the crash happens, before the fabric sends the crash report? – X-HuMan Oct 27 '17 at 08:30