Flurry should be used in Services and AsyncTasks?

做~自己de王妃 提交于 2019-12-07 08:26:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16425076/flurry-should-be-used-in-services-and-asynctasks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!