Flurry should be used in Services and AsyncTasks?
Asked Answered
C

1

4

I'm trying to use Flurry Analitcs in my app. After read a sdk document I did the following code in each activity from my application:

@Override
protected void onStart() {
    FlurryAgent.onStartSession(this, "xxxxxxxxxxxxxxxxx");
    super.onStart();
}

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

My doubt is that I have many AsyncTask and some IntentServices in my app, and in the documents they say:

Insert a call to FlurryAgent.onStartSession(Context, String), passing it a reference to a Context object (such as an Activity or Service)

So, should I call onStartSession in onHandleIntent method?? And where should I call on onEndSession? In the final process and in a finally block? And about AsyncTasks, should I implement it too even if I pass my activity context through my task?

Circumvolution answered 7/5, 2013 at 17:28 Comment(0)
L
4

The FlurryAgent exists as a singleton entity within your application. Whenever you call onStartSession() you begin a new session and calling onEndSession() will end the currently active session. This is regardless of the thread where you call FlurryAgent.

How you want to define sessions in your application is largely up to you. For most applications, a session is defined as periods of time when the user interacts with the application. This is why the documentation suggests calling onStartSession() and onEndSession() in the Activity lifecycle functions so that the session will encompass all user interactions.

If an AsyncTask is being performed while an Activity is being shown there is no need to call onStartSession() again since it will already be tracked from the enclosing Activity. If you have a background service that runs independently of Activities it is up to you when to call onStartSession().

Note that if you have a service that can run indenfinitely you should call onEndSession() periodically so that data is reported, since data is only reported when a session is started and ended.

Lessard answered 1/7, 2013 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.