package com.android.common.manager;

import com.orhanobut.logger.Logger;

/**
 * @author 910040
 * @date 2018/11/8
 * @version 1.0
 * 异常捕获处理
 * 在{@link #uncaughtException}处理
 */
public class CrashManager implements Thread.UncaughtExceptionHandler {

    private Thread.UncaughtExceptionHandler mDefaultUncaughtHandler;

    private CrashManager() {
    }

    public static CrashManager getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void init(){
        mDefaultUncaughtHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Logger.e(e, "uncaughtException");
        // NOTE 异常处理
        mDefaultUncaughtHandler.uncaughtException(t, e);
    }

    private static class SingletonHolder {
        private static final CrashManager INSTANCE = new CrashManager();
    }
}
