简体   繁体   中英

SherlockActivity with EasyTracker

I am trying to implement Google Analytics v2 in Android, together with ActionBarSherlock.

To make my life easier a bit without having to put EasyTracker code in every activities, I created a new Activity called SherlockTrackedActivity , and implement the onStart () and onStop () method for EasyTracker.

public class SherlockTrackedActivity extends SherlockActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      }

      @Override
      protected void onStart() {
        super.onStart();
        EasyTracker.getInstance().activityStart(this); // Add this method.
      }

      @Override
      protected void onStop() {
        super.onStop();

        EasyTracker.getInstance().activityStop(this); // Add this method.
      }
    }

Now I have a new Activity DemoActivity extends SherlockTrackedActivity , but the tracker doesn't work in DemoActivity ( I checked from GA Real Time).

However, if I implement SherlockTrackedActivity extends Activity directly, the tracker actually works in DemoActivity.

public class SherlockTrackedActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      }

      @Override
      protected void onStart() {
        super.onStart();
        EasyTracker.getInstance().activityStart(this); // Add this method.
      }

      @Override
      protected void onStop() {
        super.onStop();

        EasyTracker.getInstance().activityStop(this); // Add this method.
      }
    }

I wonder how can this happens?

After reading through the GA Analytics for Android https://developers.google.com/analytics/devguides/collection/android/v2/parameters

It dispatch the data on every 30 minutes (except when you close your app and start again, it does an immediate dispatch, which confused my debugging progress in above question. It's not related to SherlockActivity)

30 minutes is too weird for "Real Time tracking". Set it to a lower value and the data appear in Real Time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM