I am extending CountDownTimer in my Activity class and I am using it as a global variable in the same class. Everytime I reference to a CountDownTimer variable it is that one variable that I defined on the top. The problem that is occuring is that when ever I want to restart the timer in between (before the count down is over) , I call the cancel() method on it and I also do
myCounter = null ;
just to be on the safe side. Then I create a new instance of it using
myCounter = new MyCounter(TIMERCOUNT, TICKTIME);
what is happening is that onFinished() method is being called when I do the above and the action (I am showing a dialog box saying that the user’s time is over) is being called for no reason. If the user wants to stop the timer he can do that midway and then restart it anytime he wants. The onFinished() method should only be called when a timer successfully completes its countdown without being interrupted by the user.
That`s the way CountDownTimer works, you need to imlement a simple flag/handler of your own. See similar question here .