美文网首页
抓取Crash不让崩溃

抓取Crash不让崩溃

作者: 游侠_6fb7 | 来源:发表于2020-04-14 10:39 被阅读0次

主动抓取crash,并处理下一个消息

去掉ActivityThread类中处理消息的方法,避免黑屏

new Handler(Looper.getMainLooper()).post(new Runnable() {
    @Override
    public void run() {

        while (true) {
            try {
                Looper.loop();
            } catch (Exception e) {
                if (e instanceof QuitException) { //退出
                    return;
                }
                long realTime = SystemClock.elapsedRealtime();
                if (mTime == 0) {
                    mTime = realTime;
                } else {
                    if (realTime - mTime < 1000) {
                        mProxyCrashHandler.uncaughtException(Thread.currentThread(), e);
                    } else {
                        mTime = realTime;
                    }
                }

                StackTraceElement[] stackTraceElement = e.getStackTrace();
                for (StackTraceElement element : stackTraceElement) {
                    //目前先过滤这部分,后续可以增加系统方面的,业务方面的到时候开接口出去
                    if ("ActivityThread.java".equals(element.getFileName()) && "handleMessage".equals(element.getMethodName())) {
                        mProxyCrashHandler.uncaughtException(Thread.currentThread(), e);
                        return;
                    }
                }
                sendExceptionLog(e, ACTIVE_DEFENSE);
            }
        }
    }
});

相关文章

网友评论

      本文标题:抓取Crash不让崩溃

      本文链接:https://www.haomeiwen.com/subject/xdkzmhtx.html