Java 在未捕获异常时重新启动活动

Java 在未捕获异常时重新启动活动,java,android,uncaught-exception,Java,Android,Uncaught Exception,在活动的onCreate方法中,我运行以下命令: Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { Intent intent = getIntent();

在活动的onCreate方法中,我运行以下命令:

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                Intent intent = getIntent();
                finish();
                startActivity(intent);
            }
        });
我想做的是,在这个活动中,我想重新启动它并清除以前的意图,有了这些代码行,我最终会有一个空白屏幕,应用程序在后台运行,无论是我必须重新启动它还是从多任务屏幕上终止它,这都不是真正的用户友好。有什么想法吗?谢谢


编辑:是否也可以在此处构建警报对话框并显示一些消息?也许在OK(确定)按钮上,重定向将发生

以供将来参考,这为我带来了窍门:

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {

                Intent crashedIntent = new Intent(MainDrawer.this, MainDrawer.class);
                crashedIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                crashedIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(crashedIntent);

                System.exit(0);
            }
        });

谢谢你的建议,这是暂时的解决办法。但我不理解这些反对票:我在询问API中的一些东西,我想了解一些关于如何使用它的信息。我不是在问其他可能的建议,因为我知道这不是最好的方法。同时,我会让你报告糟糕的答案和附加的0个参数:谢谢你这是什么?我尝试了我的ErrorScreenActivity,但得到了错误:不是封闭类:ErrorScreenActivity