Thursday, July 26, 2012

[android-developers] Re: SystemClock.elapsedRealtime() drifts by up to ~1 second when the phone is in sleep mode

Leo, I am seeing this same behavior and stuggling to find a solution.  Have you worked it out yet?
I've tried implementing it in a Runnable and using SystemPreferences to store the times onPause, then retrieve them onResume  and seen this issue.  Then I moved the SystemClock.elapsedRealtime() to a service, thinking if I kept the timer running while the screen was blank that might be better.  I started testing that last night on a device and it looks like it has the same issue.

On Saturday, June 23, 2012 12:58:35 PM UTC-4, Leo Alekseyev wrote:
I am writing an app that relies on precise clock synchronization between devices.  I can sync up the clocks using NTP with good precision, and they stay in sync as long as the phones are plugged in.  However, if either phone becomes disconnected from power and goes through a few sleep/wake cycles (e.g. by pressing the power button or letting it time out), the clocks will be out of sync by 0.3 - 0.7 seconds, whereas I need millisecond precision.

My understanding was that SystemClock.elapsedRealtime() should be immune to sleep / deep sleep states. What might be going on, and is it possible to fix this behavior? In my test code, I simply have a loop inside a thread that constantly looks at elapsedRealtime and updates UI if necessary. My test devices are HTC Hero with CM7 / Gingerbread, and Nexus S 4G with ICS.

--l

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment