Catch all possible android exception globally and reload application

后端 未结 3 808
时光说笑
时光说笑 2020-12-13 15:23

I know the best way to prevent system crashes is catching all possible exception in different methods. So I use try catch blocks every where in my code. However as you know

3条回答
  •  悲哀的现实
    2020-12-13 15:36

    In your onCreate

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
                    //Catch your exception
                    // Without System.exit() this will not work.
                    System.exit(2);
                }
            });
    

提交回复
热议问题