This seems to be a common question, "how do I pause a countdowntimer"?
I found this code which looks promising:
I'm just not sure how to implement it in code. I need to override the abstracted methods and extend the class. Can someone give me an idea how to do this?
Here is your layout
Here is your activity class
Do not forget to copy CountDownTimerWithPause into your package.
Works for me, BUT...
I mention some bugs but it depends on your application. Maybe it's OK for you. Bug is - when starting timer, it fires immediatelly. 'So what?' you might ask. Imagine you click Stop button when 3 and half seconds passed. So when you click Start button you expect half second pass before you see 4, but not in that class implementation.
And there is some strange delay at the end of counting. I'd recommend to search for better implementation.
I have used
CountDownTimerWithPause
in my projects and it is pretty simple. Take a look on this sample code I just wrote to explain the implementation of this counter.Step 1
I have created sample XML layout just for better explanation later. This layout contains 3 buttons:
The layout:
Step 2
Just for this example I worked within an Activity. So this is the code:
It is easy to see how I have extended the
CountDownTimerWithPause
and which methods should be called to start,pause and resume the counter.Hope I could explain the usage of this counter.