uncaughtExceptionHandler

uncaughtExceptionHandler

是否可以在一个应用程序中将自定义UncaughtExceptionHandler与crashlytics结合在一起?如果是,怎么办?

最佳答案

由于最新版本的Crashlytics异步执行初始化,因此最好使用Fabric的初始化回调:

private static Thread.UncaughtExceptionHandler mDefaultUEH;
private static Thread.UncaughtExceptionHandler mCaughtExceptionHandler =
   new Thread.UncaughtExceptionHandler() {
     @Override
public void uncaughtException(Thread thread, Throwable ex) {
        // Custom logic goes here

        // This will make Crashlytics do its job
        mDefaultUEH.uncaughtException(thread, ex);
    }
};

CrashlyticsCore core = new CrashlyticsCore.Builder()
            .disabled(BuildConfig.DEBUG)
            .build();
Fabric.with(new Fabric.Builder(this).kits(new Crashlytics.Builder()
            .core(core)
            .build())
            .initializationCallback(new InitializationCallback<Fabric>() {
                @Override
                public void success(Fabric fabric) {
                    mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
                    Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);
                }

                @Override
                public void failure(Exception e) {

                }
            })
            .build());

关于android - Crashlytics Android SDK-自定义UncaughtExceptionHandler,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25203616/

10-08 22:31