Вопрос

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