In an Android program with two timers, I get an odd bug with one but not the other - the code seems to be the same
<p>I have an application which has two timers which should run independently of each other. I had one timer on it's own working correctly, however when I added the second I started getting an odd error. </p>

<p>The application is intended to work so that if you press the Start button next to the Jammer timer, it will begin counting down; and if you press the Start button next to the Blocker 1 timer, it will begin counting down. </p>

<p>However, what happens is if you press the button next to the Jammer timer, it will display 0. If you press the same button again, the Blocker 1 timer will begin counting down correctly. (The reverse does not happen if the button next to Blocker 1 is pressed twice) </p>

<pre><code>public void onClick(View v) {
    switch (v.getId()){

    case R.id.buttonStartJammer:
        toggleTimer(0); 
        break; 

    case R.id.buttonStartBlocker1: 
        toggleTimer(1); 
        break; 
    }

}

private void toggleTimer(final int timer){
    switch(timer){
    case 0: 
    {
        if (jammerTimerRunning) {
        jammerTimer.cancel(); 
        bStartJammer.setText(getResources().getString(R.string.start));
        } else if (jammerTimerDone){
            //stuff
        } else {
        jammerTimer = newTimer(jammerSeconds, 0); 
        jammerTimer.start(); 
        jammerTimerRunning = true;
        break; 
        }
    }
    case 1:
        if(blocker1TimerRunning){
            blocker1Timer.cancel();
            bStartBlocker1.setText(getResources().getString(R.string.start)); 
        } else if (blocker1TimerDone) {
            //stuff
        } else {
            blocker1Timer = newTimer(blocker1Seconds, 1);
            blocker1Timer.start(); 
            blocker1TimerRunning = true; 
            break; 
        }
    }

private CountDownTimer newTimer(long seconds, final int timer) {
    long milliseconds = seconds * 1000; 
    return new CountDownTimer(milliseconds,1000) {

        @Override
        public void onFinish() {
            switch(timer){
            case 0:
            {
                jammerTimerRunning = false;
                jammerTimerDone = true; 
                tvJammerTimer.setText(String.format("%d",0));
                jammerSeconds = 59; 
                break; 
            }
            case 1: 
            {
                blocker1TimerRunning = false; 
                blocker1TimerDone = true; 
                tvBlocker1Timer.setText(String.format("%d",0)); 
                blocker1Seconds = 59; 
                break; 
            }
            }
        }

        @Override
        public void onTick(long millisUntilFinished) {
            switch(timer){ 
            case 0: 
            {
                jammerSeconds = (millisUntilFinished/1000); 
                tvJammerTimer.setText(String.format("%d",jammerSeconds));
                break;
            }
            case 1:
            {
                blocker1Seconds = (millisUntilFinished/1000);
                tvBlocker1Timer.setText(String.format("%d",blocker1Seconds)); 
                break; 
            }
            }       
        }


    };
}
</code></pre>

<p>If anyone has any idea what may be causing this it'd be much appreciated. </p>
