2015-03-03 103 views
-5

在活动的onCreate方法,我在运行此:重新启动活动上uncaughtException

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { 
      @Override 
      public void uncaughtException(Thread thread, Throwable ex) { 
       Intent intent = getIntent(); 
       finish(); 
       startActivity(intent); 
      } 
     }); 

我所试图做的是,在这个活动时,我想重新启动它和以前清晰意图,用这些代码行,我最终有一个空白的屏幕和应用程序在后台运行,无论哪种方式,我必须重新启动它或从多任务屏幕杀死它,这不是用户友好的。有任何想法吗?谢谢!

编辑:是否也可以在这里建立一个警告对话框并显示一些消息?也许就OK按下,重定向会发生

+0

谢谢你的建议,这是治标不治本。我不明白downvotes虽然:)我问的东西是在API中,我想了解如何使用它的一些信息。我不是要求其他可能的建议,因为我知道这不是最好的方法 – funkycookie 2015-03-03 10:15:12

+0

同时,我只是要你报告可怜的答案和附加到它的0参数:)谢谢 – funkycookie 2015-03-03 10:20:47

回答

0

以供将来参考,这并获得成功对我来说:

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); 
      } 
     }); 
+0

这是什么MainDrawer?我试着用我的ErrorScreenActivity,我得到'错误:不是封闭类:ErrorScreenActivity' – 2017-10-27 14:20:45