王学岗崩溃捕获以及重启

package com.example.crashtest

import android.app.Application
import android.content.Context
import android.util.Log
import com.yc.toollib.crash.CrashHandler
import com.yc.toollib.crash.CrashListener
import com.yc.toollib.crash.CrashToolUtils
import com.yc.toollib.tool.ToolFileUtils
import me.weishu.reflection.Reflection

class MyApplication : Application() {
    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        Reflection.unseal(base)
    }
    override fun onCreate() {
        super.onCreate()
        initCrash()
    }

    private fun initCrash() {
         CrashHandler.getInstance().init(this@MyApplication,object : CrashListener{
             override fun againStartApp() {
                 CrashToolUtils.reStartApp3(this@MyApplication)
             }

             override fun recordException(ex: Throwable?) {
//                 可以使用WorkManager上传异常信息
                var path = ToolFileUtils.getCrashLogPath(this@MyApplication)
                 Log.i("zhang_xin","path:${path}")
                 Log.i("zhang_xin","exception:${ex?.cause}")
             }
         })
    }
}
  implementation("com.github.tiann:FreeReflection:3.1.0")

代码有毛病,没办法直接集成,需要下载到本地,把代码拷贝到项目里
代码地址

你可能感兴趣的:(随笔,android)