I was doing a basic test on "CountDownTimer" and after a particular sec i want to stop the countdowntimer completely. i used the method cancel but its not working the way i want please help me out.
below is the complete code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = (TextView)findViewById(R.id.txtView);
startTimer();
}
public void startTimer()
{
countDownTimer = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
secondsLeft = millisUntilFinished / 1000;
display.setText("seconds remaining: " + secondsLeft );
if(secondsLeft == 10)
{
display.setText("CountDownTimer Canceled");
countDownTimer.cancel();
}
}
public void onFinish() {
display.setText("done!");
}
}.start();
}