What is a correct way of determining elapsed time since last GPS Location update in pre-4.2 Androids?

StackOverflow https://stackoverflow.com/questions/23587692

  •  19-07-2023
  •  | 
  •  

Pregunta

What is a correct way to determine time since last location update on <4.2 Androids? This is code I've used:

long lastUpdateTime = lastLocation.getTime(); 
long currentTime = System.currentTimeMillis();

if (( currentTime - lastUpdateTime > 300000) ||  currentTime - lastUpdateTime < 0){
    LocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,400,1,listener);
}

Is it OK or should I have some other approach?

API Docs state this:

Note that the UTC time on a device is not monotonic: it can jump forwards or backwards unpredictably. So always use getElapsedRealtimeNanos() when calculating time deltas.

However, pre-APIv17 (where getElapsedRealtimeNanos() was added) is still around & needs to be supported.

Thanks for the answers,

¿Fue útil?

Solución

I'd leave this as a comment but I don't have that privilege yet. It seems a similar question has been asked already.

"How long ago was the last known location recorded?"

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top