Reputation:
I want to calculate how much time a user spends on my app. I thought of doing so by using chronometer. So is there an activity or something that runs always when the user is using any part of my app? or should i start and stop the timer in each and every activity?
Upvotes: 0
Views: 38
Reputation: 1275
Use Service
instead of Activity
.
Services run in background and you can access them all the time.
Upvotes: 0
Reputation: 93668
That's not the right way to do it. Use Activity lifecycle callbacks (https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks) to determine when one of your activities is paused/resumed. When one is resumed, start the timer. When one is paused, end it.
Upvotes: 2