When I press the sleep button on the device then turn it back and "update" the uptime shows the time as if the device did not go to sleep.

有帮助吗?

解决方案 2

Assuming the button you are talking about is the "power" or "lock" button, that isn't necessarily putting the device into deep sleep. In fact, looking at the definition of deep sleep (when the uptime counter will stop) I think it would be very rare. The phone will almost certainly keep the CPU running at a low level to monitor for alarm timers and other system scheduled events. If you are wanting to monitor how much time the phone is in "sleep" (screen off, phone locked etc) I suspect you will need to register a broadcast receiver and monitor for those specific events.

take a look at this thread Android - how to receive broadcast intents ACTION_SCREEN_ON/OFF? also take a look at the power manager

其他提示

From Android Reference: SystemClock:

uptimeMillis() is counted in milliseconds since the system was booted. This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms. This is the basis for most interval timing such as Thread.sleep(millls), Object.wait(millis), and System.nanoTime().

This clock is guaranteed to be monotonic, and is suitable for interval timing when the interval does not span device sleep. Most methods that accept a timestamp value currently expect the uptimeMillis() clock.

Standard functions like Thread.sleep(millis) and Object.wait(millis) are always available. These functions use the uptimeMillis() clock; if the device enters sleep, the remainder of the time will be postponed until the device wakes up. These synchronous functions may be interrupted with Thread.interrupt(), and you must handle InterruptedException.

--

Seems like your phone is idle or power saving and not technically sleeping...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top