0

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!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
zundi
  • 2,361
  • 1
  • 28
  • 45
  • You can use Fabric. They even have a crash listener so that when that listener is called you can put the log/exception to your custom server. Also, it will be available in the Fabric console. I would suggest you to use Fabric as it has many cool features. – Rahulrr2602 Mar 12 '18 at 15:26
  • 1
    Use [ACRA](https://github.com/ACRA/acra) and point it to the backend of your choice. – CommonsWare Mar 12 '18 at 15:26
  • @Rahulrr2602 Fabric is now part of Firebase, which we don't want to use at the moment. – zundi Mar 12 '18 at 15:29

2 Answers2

1

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
Aung Si Min Htet
  • 1,214
  • 3
  • 10
  • 12
0

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.

civic.LiLister
  • 2,087
  • 16
  • 13
  • 1
    Can you expand a bit on this? What would I do with this class? – zundi Mar 12 '18 at 15:39
  • Read the following post: https://stackoverflow.com/questions/8943288/how-to-implement-uncaughtexception-android https://stackoverflow.com/questions/19422366/java-uncaught-global-exception-handler – civic.LiLister Mar 12 '18 at 15:53