This question already has an answer here:
- Pausing/stopping and starting/resuming Java TimerTask continuously? 7 answers
I have a service which has one Timer. I call timer.scheduleAtFixedRate()
in the onStart()
callback method. But I have to alter the timer interval depending on the value of a variable. I found no function for timer to alter its interval. So I thought to cancel the timer and re-schedule when that condition is met. But I am checking the condition with in the timerTask itself. So when I tried to cancel the timer in the TimerTask, it throws IllegalStateException
. Can anybody give me some solution?