I'm looking to report my app crashes to a custom backend (instead of using an existing crash reporter such as Firebase).
How can I catch fatal crashes in Android?
Thanks!
I'm looking to report my app crashes to a custom backend (instead of using an existing crash reporter such as Firebase).
How can I catch fatal crashes in Android?
Thanks!
First you need to write an Exception Handler like this.
public class ExceptionHandler implements Thread.UncaughtExceptionHandler {
@SuppressWarnings("deprecation")
public void uncaughtException(Thread thread, Throwable exception) {
// Do your code here
Log.i("Localized_Message", exception.getLocalizedMessage());
}
}
Then use it by calling this class from your activity.
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler((Activity) MainActivity.this, MainActivity.class)); // Change Main Activity with your Activity
Have a try to write a class that implements interface java.lang.Thread.UncaughtExceptionHandler. In your implementation method public void uncaughtException(Thread thread, Throwable ex), the exception object is "ex" and you could do what you want there.