I use the timer schedule method to send location information to the db every 5 min.
Here is the code:
public void onStart(Intent intent, int startId)
{
this.timer.schedule(new Send(), new Date(), TEN_SECONDS*6*5); //ten_seconds = 10000
}
class Send extends TimerTask
{
public void run()
{
String address = LocationService.this.address;
new SendLocation(LocationService.this.id,address); // a thread that sends the info to the db
LocationService.this.gpsLocation = null;
LocationService.this.networkLocation = null;
}
}
But how come that my db has locations with 7/6 minute diffrence?
The sendLocation checks if the location that i’m going to send to the db is the same as the last one, if true ignore the location else send it.
Which means that the diffrence between each location in my db should be in jump of 5 minute.
There is no guarantee your
TimerTaskswill be executed exactly when you request. From theTimerdocs —and
Granted, two minutes is a long time, so there might be delays elsewhere.