Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to Kotlin SDK. enableForegroundTracking(Application app) -> onEnterForeground (timestamp: Long) #112

Open
AlbertKobyakov opened this issue Mar 15, 2023 · 1 comment
Labels
question Further information is requested

Comments

@AlbertKobyakov
Copy link

Summary

In the old version we used enableForegroundTracking(application). Kotlin SDK has an onEnterForeground(timestamp: Long) method. This method is not described anywhere, I don't understand what should be passed to the timestamp?

Old version:

Amplitude.getInstance()
         .trackSessionEvents(true)
         .initialize(applicationContext, apiKey)
         .enableForegroundTracking(application)

Kotlin SDK:

Amplitude(
         Configuration(
             apiKey = apiKey,
             context = application.applicationContext
         ).apply {
             trackingSessionEvents = true
         }
     ).apply {
         onEnterForeground(???)
     }
@AlbertKobyakov AlbertKobyakov added the question Further information is requested label Mar 15, 2023
@kelvinharron
Copy link

I wasn't aware of this functionality as I hadn't previously used the old SDK. I suspect an approach to this could be providing usage of the AndroidX Lifecycle dependency (androidx.lifecycle:lifecycle-process) and listening for resume events there. Something like this (assuming you can inject the Amplitude SDK to a service with Hilt or equivalent):

@Singleton
class MyLifecycleObserver @Inject constructor(
    private val amplitude: Amplitude
) : DefaultLifecycleObserver {

    override fun onResume(owner: LifecycleOwner) {
        super.onResume(owner)

        amplitude.onEnterForeground( // provide something like `Instant.now().toEpochMilli()`? )
    }
}

We use this approach to record an app open event without using onEnterForeground.

Some documentation could be nice here, like a default value created by Amplitude with the option of passing our own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants