I have read other posts on this topic but I do not see a clear solution. How do I set a time of 15 minutes (for example) to separate each reading of the gps ?.
As an alternative I thought about using the UITimer api and using the "Location" (Location position = LocationManager.getLocationManager (). GetCurrentLocationSync ();) But I do not know if this works or can run in the background.
My Code
class Localizacion implements LocationListener, Runnable {
private boolean inactivo = false;
private int status;
private long sesion;
private Location loc2;
private boolean primeraVez = true;
public Localizacion(long sesion) {
super();
this.sesion = sesion;
}
public void inactivaRastreo() {
this.inactivo = true;
}
public void activaRastreo() {
this.inactivo = false;
}
public void locationUpdated(Location loc) {
while (!inactivo) {
if (primeraVez) {
loc2 = loc;
primeraVez = false;
}
adicionTransaccion(loc, loc2, sesion);
loc2 = loc;
}
}
@Override
public void providerStateChanged(int newState) {
// check for unavailable errors etc.
status = newState;
}
public void run() {
while (!inactivo) {
try {
Thread.sleep(10000); // Después de cumplir este tiempo se envia el error
} catch (InterruptedException err) {
Dialog.show("Error", "No se pudo ejecutar la lectura del GPS", "Continuar", null);
inactivo = true;
}
}
}
}