Search code examples
androidtimerhandleruptime

How often will uptimeMillis() reset and will it affect Handler.postAtTime


The description for the method uptimeMillis says:

Returns milliseconds since boot, not counting time spent in deep sleep. Note: This value may get reset occasionally (before it would otherwise wrap around).

How often might this happen and (more importantly) will it affect runnables that should be executed by Handler.postAtTime?


Solution

  • The uptimeMillis call grounds out in systemTime(), which on a Linux system turns into clock_gettime(CLOCK_MONOTONIC, struct timespec *).

    The struct timespec holds seconds in a time_t, which appears to be a 32-bit value. If it starts counting near zero, you will not likely be alive when it wraps.

    If you need more specific details, you should investigate the behavior of clock_gettime(CLOCK_MONOTONIC) in the Linux kernel.