0

I need to count the phone real usage Time i.e. when the user press a button I need to start something for counting the time that the screen is on but when the user locks the phone the counter must be stopped and It must be restarted when the user unlocks the smartphone. In this way a can see a counter of hours, minutes and seconds of real smartphone usage time.

How can I approach to this logic? What kind of components can I use? Service, thread and broadcastReceiver? How can I interconnect them?

Dinal Koyani
  • 455
  • 3
  • 6
Fobi
  • 435
  • 1
  • 7
  • 17
  • You can start a background service when the application start (`onCreate()`) and end when application close/terminate (`onDestroy()`). and for pausing pause the timer on `onPause()`This way you can calculate the time – Sushin Pv Oct 26 '17 at 10:15
  • I need to record this time also when my app is in not running so the real usage time doesn't depend from my app and Its activity... – Fobi Oct 26 '17 at 10:21
  • If it is a background service. You can send a broadcast from your activity to service saying that application is started. and when the application is paused you can send another broadcast to service for pause same way you can achieve this – Sushin Pv Oct 26 '17 at 10:23
  • The fact that my application is paused does not matter because the smartphone is still used and the time counter must continue to be increased (it is still time to use the smartphone). What I'm interested in is not my application usage time but the smartphone usage time... so I need to stop the counter to every lock event and I need to restart it to every unlock event ... do you understand now? – Fobi Oct 26 '17 at 10:30

0 Answers0