每个 Activity
调用 onSessionStart(context, apikey);
和 onSessionEnd(context);
这很好地跟踪一个整个 Activity 的 session 。甚至 Fragments 也可以做同样的事情,但是当涉及到服务时(并且您认为您的 session 在服务执行操作时并未结束),在以下情况下会发生什么:
- Activity onStart() -> Flurry Start(Activity 上下文)
- Service onCreate -> Service.SomeActionIsHappening() -> Flurry Start(服务上下文)
- Activity onStop() -> Flurry Stop(Activity 上下文)
- 服务仍在运行 -> 调用 Service.SomeOtherAction() -> Flurry Start(服务上下文)
- 服务结束 -> Flurry 停止(服务上下文)。
所以余额是(无序):
- Activity 开始。
- Activity 结束。
这很好。 Activity 开始/结束计数平衡为 0。
- 服务开始。
- 服务开始。
- 服务结束。
现在,您是否需要第四次调用 end 来平衡调用? (请记住,上下文是相同的,服务调用了两次开始,但它调用了一次结束)。
或者只要来自同一上下文的最后一次调用是 onEndSession,Flurry 是否足以(且有效)接收 N 次开始和一次(或多次)结束?
Flurry 是保留引用计数(很像 Cocoa)还是仅保留上下文列表?
我还没有看到有关此特定场景的文档。所有文档都是这样说的:(强调我的)
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.
但不清楚如果相同的上下文调用开始 10 次会发生什么……
最佳答案
@323go 根据 Martin 的要求(以及对他自己的回答),文档的完整性不是问题,而是我们应该如何将 Flurry 用于服务(保持或不保持启动/停止平衡),应有的服务没有像 Activies/Fragment 那样的生命周期。
关于android - Flurry for Android 会平衡开始/结束 session 调用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23206681/