Spentak
Spentak

Reputation: 3359

Track time spent in another Android app

I know how to track time when out of the current app. For instance I could start recording time the moment my app loads another app - then if the user comes back to my app in the onResume i can end the time and calculate duration.

The problem is if the user loads the other app from my app, then presses the home button and goes and uses other apps. I don't want to track that time. I only want to track the time used in a specific app. How do I do this?

The use case of this is that this app is an education app that tracks how much time you spend in certain education apps. If the student was to close the education app and play a game app instead, I would not want to count that as valid time.

Upvotes: 1

Views: 2121

Answers (2)

Michell Bak
Michell Bak

Reputation: 13252

Something very similar was asked previously on StackOverflow, and I think you might be able to use this answer:

https://stackoverflow.com/a/4753333/762442

In short, you can use the activity manager to get a list of running tasks, and since it always returns the active task first, you'll be able to - somewhat - achieve what you're asking for.

I don't think you'll be able to track the exact time spent in each application, but you'll be able to track how long each application has been active. I don't know if that's enough for you.

Upvotes: 2

Yaroslav Mytkalyk
Yaroslav Mytkalyk

Reputation: 17115

There is no way you can do this. You can track only your Activities time.

Upvotes: 1

Related Questions