主要掌握的工具类UncaughtExceptionHandler
在activity中
ExceptionHandle exceptionHandle=new ExceptionHandle(this);
Thread.setDefaultUncaughtExceptionHandler(exceptionHandle);public class ExceptionHandle implements UncaughtExceptionHandler {
AlertDialog alertDialog=null; Builder builder=null; Activity maincontext=null; public ExceptionHandle(Activity context) {//参数必须为activity,不知道为什么 // TODO Auto-generated constructor stub maincontext=context; } @Override public void uncaughtException(Thread thread, Throwable ex) {//系统收到异常时触发方法,参数为异常触发对象和异常对象 // TODO Auto-generated method stub new Thread(){//要在子线程中显示对话框 public void run() { Looper.prepare();//必须的,不知道为什么 builder=new Builder(maincontext); builder.setTitle("程序出现崩溃"); builder.setNegativeButton("发送反馈信息", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); builder.show(); Looper.loop();//必须的,不知道为什么 }; }.start(); }}