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?