Java.util.Timer and java.util.TimerTask abomination

grrr. okay so your writing an Android app and you want some bit of code to run on a semi-regular basis. So, you create a Task, something like…

private TimerTask refreshTask = new TimerTask() {
public void run() {
//do something...
};
};

…looks like a familiar design pattern, right. So in my onResume I new a Task and schedule the bloody thing and in my onPause I call Task.cancel().

…and then you run the app and it doesn’t crash right away noooooo it waits until you have to present to your boss and then it pukes all over itself, ehhem why? Well this is just one of the many unintuitive &^%*$^ that come up all the time in Java. You spend the next couple hours borking with different ways to stop and start the timer, then you spend a bit more making sure onPause and onResume are really called when they’re supposed to, and then… You figure out that not only do you have to new a Timer every time you want to restart you also have to new a TimerTask. Why!, I don’t know why, I guess they store some state in the timer task.