I know there are a lot of threads with the same topic, but I do not want to use some random code I do not understand.
This is my current code to pause and continue a CountDownTimer in Android Studio:
public void getReadyTimer(long time){
time = 12000;
progress=0;
circularProgressBar.setProgress(0);
//tvInfo.setText("Get Ready!");
timer= new CountDownTimer(time, 1000) {
public void onTick(long millisUntilFinished) {
milliLeft = millisUntilFinished;
sec = ((millisUntilFinished-1000)/1000);
tvTimer.setText(Long.toString(sec));
//tvTimer.setText((millisUntilFinished-1000) / 1000 + "");
progress++;
int animationDuration = 1500; // 2500ms = 2,5s
circularProgressBar.setProgressWithAnimation((int)progress*100/(11000/1000), animationDuration);
circularProgressBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (t== 0) {
pauseTimer();
t =1 ;
tvInfo.setText(Integer.toString(t));
}else{
resumeTimer();
t = 0;
tvInfo.setText(Integer.toString(t));
}
}
});
}
private void pauseTimer(){
timer.cancel();
}
private void resumeTimer(){
Log.i("sec", Long.toString(sec));
milliLeft = sec*1000;
getReadyTimer(milliLeft);
}
public void onFinish() {
if (circularProgressBar.getProgress() == 100) {
startTimer();
}
}
}.start();
}
However it does not work properly. The problem is, that the Timer (after pausing) starts again with the value "time" and not with "millileft" as it should be. I appreciate every kind of help.