1

So, I'm integrating with Flurry and trying to figure out when to call FlurryAgent.onEndSession(this);.

I have four activities in my app. As there is currently only one entry point/activity adding FlurryAgent.onStartSession(this, Globals.FLURRY_API_KEY); is easy. But the problem with stopping the session is the app can be closed from any one of the four activities. Also, onStop() is called each time the app changes the activity on screen.

Has suggestions on how to decide when to end the Flurry session? Taking some advice from another answer, I could use a BaseActivity class and each of my four activities would extend this, I would then place onStart() and onStop() in there. This would solve the issue of littering my code with Flurry start/stop calls but not the issue of when to stop.

My current solution is to build on the above approach and add an exit flag. The base activity will only end the Flurry session if the exit flag is set to true.

Then, in each activity I will look catch key presses such as the back button and home key. If the home or back key is pressed I will set exit to true.

This should have the correct effect but I feel it's a bit hacky.

iOS is nice, where you only need to start the session. It would probably be a good idea to refactor my four activities into one and use Fragments. What do you guys think?

Community
  • 1
  • 1
jim
  • 8,670
  • 15
  • 78
  • 149

1 Answers1

11

You should call FlurryAgent.onStartSession from every one of your Activity's onStart methods, and onEndSession from every onStop method. As you point out, your app has multiple exit points, since the app can be backgrounded from any Activity. But for most apps following the guidelines from Google, if your user returns to the app after backgrounding it, it will return to this Activity. This should be a new session but if you only call onStartSession from your single entry point the Flurry SDK won't start a new session at that point. If you have three Activities, A, B, C all calling onStartSession and onEndSession this way, and your user navigates from A to B to C, the SDK will not report three different sessions, instead collecting the calls into a single session reported to the dashboard. Let me know if that doesn't make sense.

Using a BaseActivity to factor these calls out to an abstract class is good practice, but make sure to do the same if you use other subclasses of Activity -- BaseListActivity and so on.

(disclaimer: I work on the Android SDK at Flurry)

okonomichiyaki
  • 8,355
  • 39
  • 51
  • Suppose after calling FlurryAgent.onStartSession and no operation is done for 10s, then will the next flurry event logged in a new session or continue in same session??(before onEndSession is called) – Sjk Jun 07 '13 at 06:15
  • 1
    @Sjk If you call `onStartSession` and then call `logEvent` 10s later, without calling `onEndSession`, the session has never ended yet so the event will be logged in that session. The 10s timeout only begins after calling `onEndSession` – okonomichiyaki Jun 14 '13 at 12:19
  • thnks.if logEvent is called without calling startsession(by mistake), will it show on portal? http://stackoverflow.com/questions/17059595/flurry-if-flurry-events-added-without-start-end-session-will-it-show-on-flurry/17060016? – Sjk Jun 18 '13 at 07:19
  • 1
    They probably won't. The scenario you describe in that answer is effectively undefined behavior. – okonomichiyaki Jun 18 '13 at 14:28
  • Hi, I have also 2 questions: 1). I have 2 activities: `A` and `B` (flow: from activity `A` to activity `B`), both having `onStartSession` and `onStartSession` called in `onStart`/`onStop`. After >10 seconds after finishing activity `A` I call Flurry `logEvent` method in activity `B`. This will be logged in a new session since the default timeout is 10 seconds ? 2). Why to use multiple sessions / app / user ? Why not using a single session per application - call `onStartSession` and `onStartSession` on Application class ? Thanks! – Paul Oct 14 '13 at 12:05
  • Also one more question: 3). If I'm using `logEvent (String eventId, boolean timed)` to log a timed event and never call `endTimedEvent(String)`, what will happen with this event ? Will it ever be logged ? – Paul Oct 14 '13 at 12:28
  • Related to 3). I've posted a new question: http://stackoverflow.com/questions/19360722/flurry-timed-events-questions - please take a look if you have some time. – Paul Oct 14 '13 at 12:56
  • 1
    @Paul, I no longer work for Flurry. You may have more luck getting in touch with the support team rather than asking on Stack Overflow. – okonomichiyaki Oct 23 '13 at 16:46