【发布时间】:2015-08-13 15:08:35
【问题描述】:
我在我的应用上添加了一个新的首选项,以允许用户选择退出分析报告。我在我的应用程序 Crashlytics and Answers by Fabric 中使用。
我在 onCreate 中有这段代码:
if (PreferenceHelper.getAllowAnalytics(context)) {
Fabric.with(this, new Crashlytics());
} else {
//no crash or answers to be sent
}
}
每次我想发送一个事件时,我都会这样做:
Answers.getInstance().logCustom(new CustomEvent("test event"));
当用户允许时,这很有效。
当用户决定不允许分析时,我应该如何处理else?
【问题讨论】:
-
您可以将所有对 Answers.getInstance 的调用包装在一个新类中,该类会检查您的偏好,如果未启用则什么都不做? IE:而不是 Answers.getInstance().logCustom() WrappedAnswers.getInstance().logCustom()。包装好的答案会在 logCustom() 中进行 if/else 检查
-
@natez0r 请将此作为答案,因为这是我现在使用的路径
标签: android crashlytics twitter-fabric