你可以使用Thread.setDefaultUncaughtExceptionHandler(...)
在Application.onCreate
設置自定義Thread.UncaughtExceptionHandler
跟蹤到MixPanel所有UncaughtExceptions(崩潰),並設置屬性,如:
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));
}