本文介绍了如何使用ACRA并设置UncaughtExceptionHandler的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想设置未捕获的异常处理程序,这样我可以在事件做一个不可预见的崩溃的东西。 (我想要做的东西,喜欢接近了插座,明确通知...等)

In my application, i want to set the uncaught exception handler so that i can do stuff in the event that of an unforseen crash. (i want to do stuff like close out sockets, clear notification...etc.)

<$c$c>Thread.currentThread().setDefaultUncaughtExceptionHandler(sDefaultThreadHandler);

其中,

private static UncaughtExceptionHandler sDefaultThreadHandler = new UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        // i want ACRA to log here, then clear notifications, close out connections, cancel asynctasks...etc.

        // DO NOT REMOVE or else your app will hang when there is a crash.
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(10);
    }
};

问题是,我想向ACRA在进程退出之前还报告。我如何做到这一点?

the problem is, i want ACRA to also report before the process exits. how do i accomplish this?

推荐答案

哦,等等,NVM。我发现ACRA使用根据的),这样就意味着,如果你自己的线程有一个线程异常处理程序,将首先使用。

Oh wait, nvm. i found out that ACRA uses the default exception handler (according to https://github.com/ACRA/acra/blob/master/src/main/java/org/acra/ErrorReporter.java#L201), so that means that if your own thread has a thread exception handler, that will be used first.

Thread.currentThread()setUncaughtExceptionHandler(mYourOwnThreadHandler);

如果你真的需要使用ACRA,那么你重写 uncaughtException()方法中,仅仅通过调用发委托它向上。 。getDefaultUncaughtExceptionHandler()uncaughtException(螺纹,除息);

and if you really need to use ACRA, then inside the uncaughtException() method that you override, just delegate it upwards by calling Thread.getDefaultUncaughtExceptionHandler().uncaughtException(thread, ex);

这篇关于如何使用ACRA并设置UncaughtExceptionHandler的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 09:31