1
votes

I have an app that has 2 timers starting on their button clicks.

When they start, the timer countdown shows up in a text view so the user sees the seconds counting down (10,9,8,7, etc)

One counter is a 45 second timer, the other a 30 second timer. I have noticed that when the timers start they act one of two ways either the timer countdown shows the seconds starting at the proper one (then skips one) 45, 43, 42, 41, etc) or the other time it doesn't show the start value and jumps directly to (44, 43, 42, 41, etc) and doesn't skip any.

Ultimately I'd like these timers to show the initial value and countdown reasonably. I.e. always display 45 first, then 44, 43,42,41 etc.

Any thoughts on why this may or may not be doing it? I'm using the android CountDownTimer in my class.

Updated: here is my code for my CountDownTimer

    public CountDown (long millisInFuture, long countDownInterval, Button button ) {
    super(millisInFuture, countDownInterval);
    this.button = button;
}


//Timer Countdown
@Override
public void onTick(long millisUntilFinished) {
    long timeRemaining = (millisUntilFinished/1000);
    button.setText((millisUntilFinished/1000)+"");
1

1 Answers

0
votes

I tried to replicate the issue, but couldn't. Maybe post your code?

Here is my simple test, it displayed 45 first, then counted down sequentially, and finished on zero.

    Button b = (Button) findViewById(R.id.button1);
    final TextView tv = (TextView) findViewById(R.id.tv_1);

    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new CountDownTimer(45 * 1000, 1000) {
                int x = 45;

                @Override
                public void onTick(long millisUntilFinished) {
                    tv.setText(Integer.toString(x));
                    x--;

                }

                @Override
                public void onFinish() {
                    tv.setText("0");

                }
            }.start();

        }
    });