Android 异常捕获并重启

来源:互联网 发布:windows官网镜像 编辑:程序博客网 时间:2024/05/16 23:46

public class MyApplication extends Application implements                        Thread.UncaughtExceptionHandler{    @Override    public void onCreate(){        super.onCreate();        Thread.setDefaultUncaughtExceptionHandler(this);    }    @Override    public void uncaughtException(Thread thread, Throwable ex) {        Intent intent = new Intent(this, MainActivity.class);        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);        startActivity(intent);        System.exit(0);    }}



0 0
原创粉丝点击