From a1fe0eae1aa7d64cc64fd185e5b38003e9e66f8e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 28 May 2016 13:54:58 +0200 Subject: [PATCH] Added unhandled excpetion logging. --- .../soft/towercollector/MyApplication.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/info/zamojski/soft/towercollector/MyApplication.java b/app/src/main/java/info/zamojski/soft/towercollector/MyApplication.java index 64c474c9..b425d2b5 100644 --- a/app/src/main/java/info/zamojski/soft/towercollector/MyApplication.java +++ b/app/src/main/java/info/zamojski/soft/towercollector/MyApplication.java @@ -34,6 +34,8 @@ public class MyApplication extends Application { private static MyApplication application; private static PreferencesProvider prefProvider; + private static Thread.UncaughtExceptionHandler defaultHandler; + private static int appTheme; private static String backgroundTaskName = null; @@ -50,10 +52,23 @@ public void onCreate() { initLogger(); initEventBus(); initACRA(); + // Exception handling must be initialized after ACRA to obtain crash details + initUnhandledExceptionHandler(); initTheme(); initGA(); } + private void initUnhandledExceptionHandler() { + defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread thread, Throwable ex) { + Log.e("CRASHED", ex); + defaultHandler.uncaughtException(thread, ex); + } + }); + } + public void initLogger() { // Default configuration Log.usePrinter(Log.ANDROID, true).level(Log.I).useFormat(true);