主動抓取crash,並處理下一個消息java
去掉ActivityThread類中處理消息的方法,避免黑屏ide
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); } } } });