public class MyApplication extends Application implements Thread.UncaughtExceptionHandler { @Override public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler(this);//给线程类设置默认异常处理handler } @Override public void uncaughtException(final Thread thread, final Throwable throwable) {//异常收集工作 new Thread(new Runnable() { @Override public void run() { Looper.prepare(); System.out.print(Thread.currentThread()); Log.e("asddas","thread="+thread.getId()+"ex"+throwable.toString()); Toast.makeText(MyApplication.this, "thread="+thread.getId()+"ex"+throwable.toString(), Toast.LENGTH_SHORT).show(); Looper.loop(); } }).start(); SystemClock.sleep(3000); Process.killProcess(Process.myPid()); } }
安卓异常捕获
最新推荐文章于 2022-10-31 19:46:02 发布