Search code examples
androidcrashlyticstwitter-fabriccrashlytics-android

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


In the official documentation of Crashlytics it shows initializing Fabric in the onCreate method of an activity. I would like to have Crashlytics report crashes across the entire app, is there any downside to putting the initialization call at the Application level? Will making this change be sufficient in receiving crash reports across the entire app?

Example from documentation:

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

How I would like to do it:

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

In my testing this seems to work for my purposes, but I want to make sure this is not an anti-pattern since I can't seem to find any documentation on on it.


Solution

  • Mike from Fabric here. Yes, you can and should move it to the Application's sub-classed onCreate() if you have it. For 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."