public class UncaughtExceptionHandl implements Thread.UncaughtExceptionHandler {
private static final UncaughtExceptionHandl UncaughtExceptionHandl = new UncaughtExceptionHandl();;
private Thread.UncaughtExceptionHandler onHandler;
private Context context;
public UncaughtExceptionHandl(){
}
public static UncaughtExceptionHandl getIonter(){
return UncaughtExceptionHandl;
}
public void init(Context context){
this.context = context.getApplicationContext();
onHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
Log.i("ttt",thread.toString());
Log.i("ttt",throwable.toString());
if (onHandler!=null){
onHandler.uncaughtException(thread,throwable);
} else {
//
Process.killProcess(Process.myPid());
}
}
}
创建一个App调用
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
UncaughtExceptionHandl.getIonter().init(this);
}
}