赞
踩
2、覆写UncaughtExceptionHandler 的onCreate 和uncaughtException 方法。
- @Override
- public void onCreate() {
- super.onCreate();
- Thread.setDefaultUncaughtExceptionHandler(this);
- }
- @Override
- public void uncaughtException(final Thread thread, final Throwable ex) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- Looper.prepare();
- System.out.println(Thread.currentThread());
- Toast.makeText(getApplicationContext(), "thread="+thread.getId()+"ex="+ex.toString(), 1).show();
- Looper.loop();
- }
- }).start();
- SystemClock.sleep(3000);
- android.os.Process.killProcess(android.os.Process.myPid());
- }
注意:上面的代码只是简单的将异常打印出来。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。