Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How to get the time the screen of a device is on in my android app?

I want to know how long the screen of my users device is on, i only need the time that has been on.

1 Answer

Hey, it's a lot to type so I will give you the link, but think about it like this (if you haven't already). When I set my screen timeout I can set it to a certain value. Then my screen will be on for x amount of time. So android must have interaction with this, and it must be keeping track of how long the screen is on so it can shut off at the desired time. The link below uses gestures and detection of those with a lot of different support libraries you can use to accomplish your task.

https://developer.android.com/training/gestures/detector.html

Hope this helps.