سؤال

Each Activity calls for onSessionStart(context, apikey); and onSessionEnd(context); and this is fine to keep track of a session throughout activities. Even Fragments could do the same, but when a Service is involved (and you consider that you session is not ended while the service is doing stuff), what will happen in the following scenario:

  1. Activity onStart() -> Flurry Start (Activity Context)
  2. Service onCreate -> Service.SomeActionIsHappening() -> Flurry Start(Service Context)
  3. Activity onStop() -> Flurry Stop (Activity Context)
  4. Service Still Running -> calls Service.SomeOtherAction() -> Flurry Start(Service Context)
  5. Service Ends -> Flurry Stop (Service Context).

So the balance has been (in no order):

  1. Activity Start.
  2. Activity End.

This is fine. The activity start/end count is balanced to 0.

  1. Service Start.
  2. Service Start.
  3. Service End.

Now, do you need to call end a fourth time to balance the calls? (remember that the context was the same, the Service called start two times, but it's calling end once).

Or is it enough (and valid) for Flurry to receive N number of starts and one (or more) ends as long as the last call from the same context was onEndSession?

Does Flurry keep a reference count (much like Cocoa) or just a context list?

I haven't seen documentation regarding this specific scenario. All the documentation says is this: (emphasis mine)

Make sure to match up a call to onEndSession for each call of onStartSession, passing in the same Context object that was used to call onStartSession. Note: So long as there is any Context that has called onStartSession but not onEndSession, the session will be continued. If a new Context calls onStartSession within 10 seconds of the last Context calling onEndSession, then the session will be resumed, instead of a new session being created. This ensures that as a user transitions from one Activity to another in your app, that they will not have a separate session tracked for each Activity, but will have a single session that spans many activities.

But it's not clear what happens if the same context calls start 10 times…

هل كانت مفيدة؟

المحلول 2

According to my experience, yes it will balance calls. Recently I made mistake of tying Flurry sessions to Accessibility Service OnCreate/OnDestroy and session never finished which result in no analytics being sent (Accessibility Service are run forever if enabled by user)

نصائح أخرى

@323go based on what Martin is asking (and answer to him self) is not a matter how complete the documentation is, instead how we should use Flurry into a service (to keep or not to keep start/stop balanced), due service do not have same life cycle like Activies/Fragment have.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top