Android - Crashlytics, run code during crash

前端 未结 3 1686
北海茫月
北海茫月 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:02

    As @basu-singh said, you can add context to the crash, see https://docs.fabric.io/android/crashlytics/enhanced-reports.html

    Or you can use your own UncaughtExceptionHandler, and then call Crashlytics. Though your code needs to be extra safe !

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
  • 2021-01-28 03:18

    No you can't. You can however set certain values before initiating Crashlytics. Like adding values to parameters so as to identify user. Like adding email id of user before creating a crashlytics session.

    0 讨论(0)
提交回复
热议问题