Does Firebase Analytics need to be initiated in all activities?

Asked

Viewed 49 times

2

I am in an uncomfortable impasse. I am creating the habit of using Firebase in my project, but I do not understand how to use it. I need to put the Firebase Analytics code on all activities or in just one?

1 answer

1

According to the notes of Version 9.8 - October 24, 2016 from the Firebase Android SDK the Automatic Screen Tracking (automatic screen tracking) is already supported by Firebase Analytics on Android, while for ios for a while. For more details you can follow the guidelines in documentation of Firebase Analytics.

However, an alternative to not need to start at all Activities, would create a global variable in a class that extends the class Application:

public class MyLittleApplication extends Application {
    public static  FirebaseAnalytics fbAnalytics;
    @Override
        public void onCreate() {
        super.onCreate();
        fbAnalytics= FirebaseAnalytics.getInstance(this);
    }
}

In the manifest.xml you use the tag <application > in this way:

<application
  android:name=".MyLittleApplication" ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.