Skip to content

Android app support, for native Error and java Exception. this library will keep your app away from crash. And It's really easy to use.

Notifications You must be signed in to change notification settings

chunfengyao/module_app_ops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

说明文档。

注册方式

class CodeBlock{
    private val nativeErrors = intArrayOf(
        SysSignalConst.SIGILL,
        SysSignalConst.SIGTRAP,
        SysSignalConst.SIGABRT,
        SysSignalConst.SIGBUS,
        SysSignalConst.SIGFPE,
        SysSignalConst.SIGSEGV,
    )
    fun init(){
        DefaultExceptionHandler.getInstance().regist(this,
                object:DefaultExceptionHandler.ExceptionHandler{
            override fun onExceptionOccured(
                    exception: Throwable,
                    occuredOnUIThread: Boolean
                ) {
                ToastUtil.showCenter(
                        "UI线程?${occuredOnUIThread},收到Java异常:${exception.message}"
                )
            }
        },
        false,
                nativeErrors,
                object : NativeErrorHandler {
            override fun onSysSignalRec(
                    context: Context,
                    signal: Int,
                    nativeStackTrace: String,
                    currentThread: Thread
                ): Boolean {
                ToastUtil.showCenter(
                        "收到Native异常:$nativeStackTrace"
                )
                return true
            }
        })
    }
}

测试代码

class CodeBlock{
    public void testNative() {
        //测试native的错误
        NativeErrorManager.raiseNativeSignal(SysSignalConst.SIGBUS);
    }
    public void testJava(){
        //测试java的错误
        throw new NullPointerException("测试异常");
    }
}

注意点

  • com.yaocf.support.provider.ContextProvider会在App启动时自动启动。
  • 如果需要将注册代码放到onAttachBaseContext中,请将相关的所有类,加入到MultiDex的主Dex中(参见:Android配置multidex
    • 该做法可以更大范围地捕捉和控制异常。

About

Android app support, for native Error and java Exception. this library will keep your app away from crash. And It's really easy to use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published