Android应用崩溃后异常捕获并重启

来源:互联网 发布:淘宝模特拍摄现场 编辑:程序博客网 时间:2024/04/30 00:42
public class MyApplication extends Application implementsThread.UncaughtExceptionHandler {@Overridepublic void onCreate() {super.onCreate();//设置Thread Exception HandlerThread.setDefaultUncaughtExceptionHandler(this);}@Overridepublic void uncaughtException(Thread thread, Throwable ex) {System.out.println("uncaughtException");Intent intent = new Intent(this, MainActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);
                System.exit(0);
}}
最后需要在Manifest中配置Application的标签android:name=
原创粉丝点击