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?