private static UncaughtExceptionHandler getUncaughtExceptionHandler(final String dirPath, final OnCrashListener onCrashListener) { return new UncaughtExceptionHandler() { @OverRide public void uncaughtException(@nonnull final Thread t, @nonnull final Throwable e) { final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss").format(new Date()); CrashInfo info = new CrashInfo(time, e); final String crashFile = dirPath + time + ".txt"; UtilsBridge.writeFileFromString(crashFile, info.toString(), true);
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}
if (onCrashListener != null) {
onCrashListener.onCrash(info);
}
}
};
}
5条答案
按热度按时间qoefvg9y1#
private static UncaughtExceptionHandler getUncaughtExceptionHandler(final String dirPath,
final OnCrashListener onCrashListener) {
return new UncaughtExceptionHandler() {
@OverRide
public void uncaughtException(@nonnull final Thread t, @nonnull final Throwable e) {
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss").format(new Date());
CrashInfo info = new CrashInfo(time, e);
final String crashFile = dirPath + time + ".txt";
UtilsBridge.writeFileFromString(crashFile, info.toString(), true);
ma8fv8wu2#
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}
此处代码会阻塞后续监听
wj8zmpe13#
@Blankj
kxxlusnw4#
我也发现这个问题了,但是又不知道怎么覆写。
h22fl7wq5#
我也发现这个问题了,但是又不知道怎么覆写。
if (onCrashListener != null) {
onCrashListener.onCrash(info);
} else if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}
我代码复制过来重写了这块