I'm trying decide which of the following is the proper way to do this:
FirebaseAnalytics.getInstance(Context)
from every activity, fragment, and service that I'm logging an event from.or
FirebaseAnalytics.getInstance(Context)
once from Application
class and keeping it around as a public static variable. Then, from everywhere I need this I can call `MyAppClass.mFirebaseAnalytics.logEvent()'.Will any of the above methods have a undesired impact on the events that are automatically collected and/or do either of those have an efficiency gain over the other?
Many thanks!
The documentation states:
public static FirebaseAnalytics getInstance (Context context)
Returns the singleton FirebaseAnalytics interface.
So I don't see any particular reason why you can't just have a singleton instance in your code. There won't be any noticeable efficiency gains with either approach. If you're looking into the second option, it might be worth considering doing this with dependency injection and a simple wrapper around the analytics instance to increase the testability of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With