Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Report Custom events to Crashlytics without actually killing the process.
public class CrashReporting {
public static class GenericReportingException extends Exception {
public GenericReportingException(){}
public GenericReportingException(String str){
super(str);
}
}
/**
* Report Crash to crashlytics without killing the process
* @param exception
*/
public static void reportCrash(GenericReportingException exception) {
if(exception == null) return;
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), exception);
}
}
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
//Must init in this order
installCrashHandler();
startCrashlytics();
}
/**
* initialized Crashlytics with this Application Object Context
**/
private void startCrashlytics() {
Crashlytics.start(getApplicationContext());
}
/**
* installed a custom Crash Handler that will not actually crash the app using a GenericReportingException object
**/
private void installCrashHandler() {
private void installCrashHandler(){
//The real UncaughtExceptionHandler
final Thread.UncaughtExceptionHandler realExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
if(ex instanceof CrashReporting.GenericReportingException) {
//Starting this again because it is unregistered on the completion of Crashlytics UncaughtExceptionHandler
startCrashlytics();
return;
}
realExceptionHandler.uncaughtException(thread, ex);
}
}
}
}
@azrashaikh

This comment has been minimized.

Copy link

azrashaikh commented Aug 31, 2015

I am not able to get method Crashlytics.start(this);
I guess this one is deprecated in latest build.
I am using Crashlytics - 2.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.