you cannot do this because it will fix it with a Timer after completing the schedule.
Schedules the specified task for repeated execution with a fixed delay, starting from the specified delay. Subsequent executions are carried out at approximately equal intervals divided by the indicated period.
In this case, you can undo the previous one and schedule a new TimerTask.
Timer timer = new Timer(); initialize the speed here loop based on time timer.schedule(new TimerTask() { // @Override @Override public void run() { here is the code, and i do Speed = Speed-500 }, Speed,Speed);
source share