title: How to use intervals in Android CountdownTimer
body: <p>I am creating a countdown time in Android and I have the timer part working perfectly. However, I want to add a feature where the user can set the number of times they wish the timer to repeat. This is my current attempt at implementation</p>
  
  <pre><code>    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      textView = (TextView) findViewById(R.id.textView);
      minutesText = (EditText) findViewById(R.id.minutesText);
      secondsText = (EditText) findViewById(R.id.secondsText);
      startButton = (Button) findViewById(R.id.startButton);
      intervalCount = (EditText) findViewById(R.id.intervalCount);
  
  
  
  
  
  
      startButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              if (minutesText.getText().toString().equals("")) {
                  minutesInt = 0;
              } else {
                  minutesString = minutesText.getText().toString();
                  minutesInt = Integer.parseInt(minutesString);
  
              }
  
              secondsString = secondsText.getText().toString();
              if (secondsText.getText().toString().equals("")) {
                  secondsInt = 0;
  
              } else {
                  secondsString = secondsText.getText().toString();
                  secondsInt = Integer.parseInt(secondsString);
  
              }
              intervalsString = intervalCount.getText().toString();
              intervals = Integer.parseInt(intervalsString);
  
  
              final int timerAmount = ((minutesInt * 60) + (secondsInt)) * 1000;
              CountDownTimer timer = new CountDownTimer(timerAmount, 1000) {
                  @RequiresApi(api = Build.VERSION_CODES.N)
                  public void onTick(long millisUntilFinished) {
                      isRunning = true;
                      String timeLeft = String.format("%02d : %02d",
                              TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished),
                              TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
                              TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))
                      );
                      textView.setText("Reamining: " + timeLeft);
                  }
                  public void onFinish() {
                      isRunning = false;
                      intervals--;
                      if (intervals &gt; 0) {
                          timer.start();
                      }
  
  
                      try {
                          Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                          Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
                          r.play();
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              };timer.start();
  
          }
      });
  </code></pre>
  
  <p>My error is in the onFinish()
  it wont let me use timer.start()</p>