1

I am trying to log the exceptions, caught using the global exception handler in one of my Android application. The overall strategy is simple, the app should not terminate in case of an exception, if they're an exception, catch that, log to Crashlytics and restart the application.

Following is the part of the code, which handles the exception and log that to Crashlytics.

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread thread, Throwable e) {
                    Crashlytics.log(Log.ERROR, "Global Catch Handler", e.toString());
                    if(Preferences.getInstance().isReachRunning(SyncApplication.this)){
                        Intent freshIntent = new Intent(SyncApplication.this, AppMainActivity.class);
                        freshIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        SyncApplication.this.startActivity(freshIntent);
                        Process.killProcess(Process.myPid());
                        System.exit(10);
                    }
                }
            });

This seems to work fine as far as exception catching and restarting the app goes, but I am not able to see any log in the Crashlytics dashboard.

I also tried adding Crashlytics.logException without any luck

What I think that, because I am killing the process, somehow Crashlytics misses the logging part. Anyone can guide me through the right process which can help me logging the errors to Crashlytics dashboard?

Tejashwi Kalp Taru
  • 2,994
  • 2
  • 20
  • 35
  • The order matters while settings Fabric and your custom exception handler. Initialize fabric first and then setup your exception handler. PS: Crashlytics.logException will log the exception under "Non fatal" so you might need to select the option on the Crashlytics dashboard. – Furkan Yurdakul Mar 27 '19 at 14:26
  • Check https://stackoverflow.com/a/49266303/6276596 this answer for more information. – Furkan Yurdakul Mar 27 '19 at 14:28

0 Answers0