Reputation: 2457
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!
Upvotes: 0
Views: 683
Reputation: 1214
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
Upvotes: 1
Reputation: 2197
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.
Upvotes: 0