Created
August 13, 2013 01:10
-
-
Save tyvsmith/6216923 to your computer and use it in GitHub Desktop.
Report Custom events to Crashlytics without actually killing the process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
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
http://stackoverflow.com/questions/25203616/crashlytics-android-sdk-custom-uncaughtexceptionhandler/29073235#29073235