I have searched this site for an answer for what I'm seeing in my Android Marshmallow application.
My application measures the duration between activitydetection api intents received. In the routine that process the intents, I use System.nanoTime()
and persist the value received. On receipt of the next intent I subtract the previous System.nanoTime()
time from persisted storage from the current System.nanoTime()
.
My logcat timestamp entry indicates that ~10 seconds occur between intent activites. Calculated elapsed time, using System.nanoTime
, is showing anywhere from 1 to the expected 10~seconds.
All processing to determine the elapsed time are done in a singleton object. Both the calculated elapsed duration and persisting of the current nano time are done in this singleton.
Any ideas why the values are incorrect? My application is running but the screen is locked.
protected synchronized int distanceUpdate(Cursor dbCursor, String activity){
...
long currentNanoTime = 0;
long tmpTotDuration = 0;
...
currentNanoTime = System.nanoTime();
...
tmpTotDuration +=(currentNanoTime - lastTotalTime);
Where lastTotalTime is local variable loaded from persisted storage. Changed to
ecurrentNanoTime = SystemClock.elapsedRealTimeNanos();