I am creating an application that should determine the running time of the application, so I can show user statistics of the applications that it uses. I found several solutions on the Internet, but they all have their drawbacks.
Here are the two best options I've found:
I also looked for the intention to shoot when the application starts or stops, but it seems to be none (see the summary). This post confirms this. I also found a class: ActivityLifecycleCallbacks , which receives callbacks when the activity state changes. But this is only for internal use (read inside your own application).
So, my idea is to use the service to poll the current foreground application on devices running a version other than lollipop, and use the new API on devices running on candy or more. But is this a βserviceβ idea a better option because, as I said, it seems like an inefficient battery? Maybe there are better options?
Faas
source share