Skip to content

Instantly share code, notes, and snippets.

@tyvsmith
Created August 13, 2013 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tyvsmith/6216923 to your computer and use it in GitHub Desktop.
Save tyvsmith/6216923 to your computer and use it in GitHub Desktop.
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
Copy link

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