本文主要是介绍王学岗崩溃捕获以及重启,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package com.example.crashtestimport 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.Reflectionclass 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")
代码有毛病,没办法直接集成,需要下载到本地,把代码拷贝到项目里
代码地址
这篇关于王学岗崩溃捕获以及重启的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!