segmentio / analytics-kotlin

The hassle-free way to add Segment analytics to your Kotlin app (Android/JVM).

Repository from Github https://github.comsegmentio/analytics-kotlinRepository from Github https://github.comsegmentio/analytics-kotlin

question: What's the purpose of `useLifecycleObserver` option?

lwasyl opened this issue · comments

Basically title, the default value is false, when would/should I set it to true? I want to track application lifecycle events so I'm setting trackApplicationLifecycleEvents to true but I don't know what's the significance of useLifecycleObserver. The documentation just says enables the use of LifecycleObserver to track Application lifecycle events but it doesn't explain what I should consider when enabling this flag

hi @lwasyl, trackApplicationLifecycleEvents = true tracks lifecycle events regardless the value of useLifecycleObserver, though in different ways. if useLifecycleObserver = false, lifecycle events are tracked via the old android lifecycle hooks ActivityLifecycleCallbacks. otherwise, lifecycle events are tracked via DefaultLifecycleObserver

for example, on activity created, if useLifecycleObserver = false, the sdk calls to the override method onCreated from DefaultLifecycleObserver explicitly to track lifecycle events. however, if useLifecycleObserver = true, onCreated is invoked by the lifecycle observer automatically. the end results are the same. choose the value that fits your use case.

Hi, thanks but that doesn't really answer my question - what would be my use case for using one or the other? As a library consumer I still don't know if I should change the default or not. If both options work the same, why have it configurable in the first place?

if you already use lifecycle observer in your app, you can set useLifecycleObserver = true, but you don't have to. this flag is designed for the apps that did not implement lifecycle observer.