I have created my own class that extends CountDownTimer. Since I use it often, I would like to have that class in its own java file.
However, I do not know of a way for the timer class to communicate with the class that created it.
Example: class A has a textView that displays some number of seconds. So, class A creates the timer.
- How can the onTick() method in CountDownTimer be told to update my
textView with the current time? - How can my class A know when the timer has finished?
I’m sure it’s a simple answer, I just know very little about threads, handlers, listeners, and whatever else you wizards are cooking up.
This should be very similar using a regular countdown timer – just substitute your subclass for the regular timer instance. Also, pass the activity into the constructor so it can do whatever it needs to update the display.
E.g.
Where MyCountownTime would have methods like this:
This assumes mActivity is passed in the constructor. I changed the code to assume the calling activity was passed as a variable in the timer constructor and set as a member of the timer class.