1

I need to use Flurry within a Fragment in my Android app.

I insert the following code in onStart():

@Override
public void onStart() {
    super.onStart();
    //Log.i("About get activity","About get activity "+getActivity().hashCode());
    FlurryAgent.onStartSession(getActivity(), "WXXXXXXXX");
}

and in on stop:

@Override
public void onStop() {
    FlurryAgent.onEndSession(getActivity());
    super.onStop();
}

Is this code correct? Do I pass the context as getActivity(), this or something else?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Anirudh
  • 2,080
  • 5
  • 21
  • 34

1 Answers1

0

That's correct, you could also use:

getActivity().getApplicationContext();

which is the context for the entire application and not specific to that particular Activity.

As a side note, if it happens to you to get some weird crashes, specially when you press quickly the back button removing all the fragment in your back stack, it may be that getActivity() is returning null.

fasteque
  • 4,309
  • 8
  • 38
  • 50
  • If my app has one activity and four fragments then Will flurry report four different sessions for each fragment or it will be just one session?Can you please elaborate. – Ashwin N Bhanushali Jun 12 '14 at 11:36
  • Official Flurry documentation for onStartSession and onEndSession explain it very clearly: http://support.flurry.com/index.php?title=Analytics/Code/Doc/Android – fasteque Jun 12 '14 at 11:40
  • Hi @fasteque I use google analytics and I can't see apps' fragments in google analytics, Only I can see FragmentActivity. If I use Flurry, can I see fragments in Flurry ? – Olkunmustafa Aug 29 '14 at 09:50
  • @MustafaOlkun fragments are part of the Android framework, not Flurry or Google Analytics. What's your problem? I suggest you to ask a new question will all the information about the issue you are facing. Thanks. – fasteque Aug 29 '14 at 09:58
  • @fasteque I've asked before there ==> http://stackoverflow.com/questions/25473383/how-to-track-fragments-in-my-application-with-google-analytics Thank you. – Olkunmustafa Aug 29 '14 at 10:23