Need to handle uncaught exception and send log file

后端 未结 7 903
时光说笑
时光说笑 2020-11-22 15:42

UPDATE: Please see \"accepted\" solution below

When my app creates an unhandled exception, rather than simply terminating, I\'d like to first give t

7条回答
  •  清歌不尽
    2020-11-22 16:25

    Handling uncaught Exceptions: as @gilm explained just do this, (kotlin):

    private val defaultUncaughtHandler = Thread.getDefaultUncaughtExceptionHandler();
    
    override fun onCreate() {
      //...
        Thread.setDefaultUncaughtExceptionHandler { t, e ->
            Crashlytics.logException(e)
            defaultUncaughtHandler?.uncaughtException(t, e)
        }
    }
    

    I hope it helps, it worked for me.. (:y). In my case I've used 'com.microsoft.appcenter.crashes.Crashes' library for error tracking.

提交回复
热议问题