4

I am working on an Android Application which is integrated with MixPanel for analytics and BugSnag for error monitoring.

Recently we found crash in the application and as we couldn't find the root cause of the crash we added code to restart the app when the bug occurs. Along with restart, we also started tracking how many times the bug occurs. My preference was to use Bugsnag for the same, but couple of people in the team asked why can't we use MixPanel because we can easily filter out the events with parameters which we sent to MixPanel. But I feel MixPanel shouldn't be used as its specifically for tracking user events. And neither the crash nor the restart happens because of a user event, it just happens randomly.

I would like to hear suggestions/thoughts from the community regarding the same.

4

1 回答 1

0

您可以使用Thread.setDefaultUncaughtExceptionHandler(...)在您Application.onCreate的自定义设置Thread.UncaughtExceptionHandler跟踪到 MixPanel 所有未捕获异常(崩溃)并设置属性,例如:

public class MyExceptionHandler implements UncaughtExceptionHandler
{
    private UncaughtExceptionHandler defaultExceptionHandler;

    public MyExceptionHandler (UncaughtExceptionHandler defaultExceptionHandler)
    {
        this.defaultExceptionHandler = defaultExceptionHandler;
    }

    public void uncaughtException(Thread thread, Throwable exception)
    {
        mMixPanelInstance.trackEvent("APP_CRASH", null);
        if (defaultExceptionHandler != null)
        {
            defaultExceptionHandler.uncaughtException(thread, exception);
        }

    }
}


MyApplication.onCreate(...)
{
    UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(currentHandler));
}
于 2015-03-27T23:36:59.223 回答