在应用程序级别初始化 Fabric 和 Crashlytics 有什么缺点吗?

Is there any downside to initializing Fabric & Crashlytics at the Application level?

在 Crashlytics 的官方文档中,它显示了在 activity 的 onCreate 方法中初始化 Fabric。我想让 Crashlytics 报告整个应用程序崩溃,将初始化调用放在应用程序级别有什么缺点吗?进行此更改是否足以接收整个应用程序的崩溃报告?

文档中的示例:

public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Fabric.with(this, new Crashlytics());
      setContentView(R.layout.activity_main);
    }
}

我想怎么做:

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        Fabric.with(this, new Crashlytics());
        super.onCreate();
    }
}

在我的测试中,这似乎符合我的目的,但我想确保这不是反模式,因为我似乎找不到任何关于它的文档。

应用程序一直存在,直到您的 android 应用程序进程被终止。 您可以使用它来存储可能在各种活动中使用的特定于应用程序的数据(只要您的应用程序处于活动状态)。

由于 Fabric 需要在应用程序启动时进行初始化,因此最好在应用程序中对其进行初始化 class。

这里是来自 Fabric 的迈克。是的,您可以而且应该将其移至应用程序的子类 onCreate()(如果您有)。对于 reference

"If you have an Application subclass, then you can place Fabric.with() in the onCreate() method. Otherwise, if you have multiple launch activities in your app, then add Fabric.with() to each launch activity. Fabric is only initialized the first time you call start, so calling it multiple times won’t cause any issues."