0

在 Android 中,发生错误时会提示运行时错误对话框。是否可以隐藏它?或者只是在生产模式下隐藏它?因为它显示了一些不应该向用户公开的应用程序的错误消息。

4

2 回答 2

0

Thread.setDefaultUncaughtExceptionHandler(..)您可以在主线程上为未捕获的异常设置自定义处理程序。在那里你可以做你需要做的事情,包括如果你使用以下模式调用默认行为:

public class ExceptionHandler implements UncaughtExceptionHandler
{
    /**
     * The default handler.
     */
    private UncaughtExceptionHandler defaultUEH;

    /**
     * Constructs the instance and sets the default handler to the one currently
     * active at the time of construction.
     */
    public ExceptionHandler() 
    {
        this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex)
    {
        // do your stuff            

        // if you want to resume with the default behaviour, you call this
        defaultUEH.uncaughtException(thread, ex);
    }
}

在你的Activity/ Application

Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
于 2013-01-28T11:55:38.620 回答
0

您应该避免您的应用程序达到强制关闭,当您的应用程序最终强制关闭时,您的主线程已被杀死并且您的应用程序不再运行并且在编码中无法访问,因此您可以创建另一个线程并处理情况并显示给用户的自定义对话框。

也许Github 中的Acra会帮助你处理这个问题。

于 2013-01-28T11:27:36.880 回答