Whenever your app receives new Notification, Application OnCreate()
method will be invoked.
Not only the Notification, even when you subscribe to system events like ACCESS_WIFI_STATE, ACCESS_NETWORK_STATE, RECEIVE_SMS, RECEIVE_BOOT_COMPLETED.. Application OnCreate() will be invoked.
So inside your Application OnCreate()
, don't make any Google Analytics related calls.
This will initialize your GA and start the event tracking.
Remove Google Analytics related codes inside your Application OnCreate()
, to prevent unwanted event tracking.
Update:
https://developers.google.com/analytics/devguides/collection/android/v4/advanced
getInstance(Context context)
Gets the GoogleAnalytics instance, creating it when necessary.
Multiple way of implementation around this; I recommend you the following way to solve your problem. As document says, prepare the GoogleAnalytics instance, only when it is needed.
Keep the below code inside your Application class, so that your mTracker
instance will alive across your application lifecycle.
// Inside Application class
private Tracker mTracker = null;
public synchronized Tracker getDefaultTracker() {
if (mTracker == null) {
// Prepare the GoogleAnalytics instance, only when it is needed.
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
mTracker = analytics.newTracker(Config.GA_TRACKING_ID);
mTracker.enableAutoActivityTracking(true);
mTracker.enableExceptionReporting(true);
mTracker.setSessionTimeout(SESSION_TIMEOUT);
}
return mTracker;
}
Hope this would help you..