Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法捕获所有错误并执行操作,例如在 Toast 中显示错误消息并重新启动应用程序而不会崩溃?
我们所做的是Thread.setDefaultUncaughtExceptionHandler在 UI 线程上设置一个全局处理程序。在处理程序中,我们获取堆栈跟踪并向自己发送报告,然后调用
Thread.setDefaultUncaughtExceptionHandler
Process.killProcess(Process.myPid()); System.exit(0);
优雅地重启