0

I want to set up analytics for my app and it says The method getActivity() is undefined for the type MainScreen. I have setted up the 'MyAplication, and there I'm getting no errors, so this is the mainscreen code:

@Override
    public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

    Tracker t = ( (MyApplication) getActivity().getApplication()).getTracker(
                      TrackerName.APP_TRACKER);

                  // Set screen name.
                  t.setScreenName("MainScreen");

                  // Send a screen view.
                  t.send(new HitBuilders.ScreenViewBuilder().build());



    } 
Emanuel Graf
  • 756
  • 17
  • 37
  • 1
    This thread might answer your question : http://stackoverflow.com/questions/24950341/android-google-analytics-integration-error – flafoux Apr 11 '15 at 15:22

1 Answers1

1

The Activity class doesn't have getActivity() method. If you need to access the activity use this. instead (or just call the activity method directly). You probably copied the code from a Fragment example. Fragments are not activities and you need to get access to the activity with getAcitivty() method

djabi
  • 5,601
  • 18
  • 25