Android - Crashlytics, run code during crash

前端 未结 3 1695
北海茫月
北海茫月 2021-01-28 02:30

I had a bad crash case that was caused due to some Asyncs doing stuff in improper order in a SQLite and thing blew up. It took me some time to debug all that and access to the i

3条回答
  •  野的像风
    2021-01-28 03:12

    It is possible to get control prior to Crashlytics logging a crash. You essentially have to create your own uncaught exception handler and call Crashlytics' handler from there. Something like this in your Application class:

    private UncaughtExceptionHandler originalUncaughtHandler;
    
    @Override
    public void onCreate() {
        // initialize Fabric with Crashlytics
    
        originalUncaughtHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    
        // do the rest of your oncreate stuff
    }
    
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        // do your work to add data to Crashlytics log
    
        originalUncaughtHandler.uncaughtException(thread, ex);
    }
    

提交回复
热议问题