new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
while (true) {
try {
Looper.loop(); //try-catch主线程的所有异常;Looper.loop()内部是一个死循环,出现异常时才会退出,所以这里使用while(true)。
} catch (Throwable e) {
Log.d(TAG, "Looper.loop(): " + e.getMessage());
}
}
}
});
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) { //try-catch子线程的所有异常。
Log.d(TAG, "UncaughtExceptionHandler: " + e.getMessage());
}
});