Google Analytics in Android app - dealing with multiple activities

后端 未结 7 2199
忘了有多久
忘了有多久 2020-11-28 18:42

I was pretty excited to see how easy it is to set up Google Analytics with my app, but the lack of documentation has me sitting with a few questions. The only information th

7条回答
  •  清酒与你
    2020-11-28 19:08

    The tracker will only track the activity where it's executed. So, why don't you subclass an Activity which start it every time on onCreate:

    public class GAnalyticsActivity extends Activity{
    
        public void onCreate(Bundle icicle){
            super.onCreate(icile);
            tracker = GoogleAnalyticsTracker.getInstance();
            tracker.start("UA-xxxxxxxxx", this);
        }
    
        // same for on destroy
    }
    

    Then, you extends that class for every activity you use:

    public class YourActivity extends GAnalyticsActivity{
        public void onCreate(Bundle icicle){
            super.onCreate(icile);
            // whatever you do here you can be sure 
            // that the tracker has already been started
        }
    }
    

提交回复
热议问题