문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top