1

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();
MrMagoo
  • 67
  • 1
  • 12
  • Where is the code. – petey Jun 14 '16 at 13:39
  • Too little information imho to provide a useful answer here. I can still advise you to narrow the incognita by using an alternative method to track your activities (play a sound, write a file, connect to a server) in order to better understand what's happening... – Rick77 Jun 14 '16 at 13:43
  • Swapped out the use of System.nanoTime() to SystemClock.elapsedRealtimeNanos() and my initial parse of the logcat entries generated shows a match between the logcat entry timestamp for the method in question and the calculated elapsed time. – MrMagoo Jun 14 '16 at 13:50
  • to clarify: Using the ActivityRecognitionApi to request activity updates every 10 seconds. Sending intents received using PendingIntent.FLAG_UPDATE_CURRENT. The IntenetService processing the intent checks for certain activities. If a matching activity is found, a method is called in a singleton object that calculates duration between events and persists values for the next event. System.nanoTime() returns incorrect values but SystemClock.elapsedRealtimeNano() time value is correct. calls to collect this information are made in a synchronized method. – MrMagoo Jun 14 '16 at 14:02

0 Answers0