0

I made a button that starts a Chronometer and I want to make the Chronometer restart after 15 minutes (to be looping). I am new to coding and I don't know how to manage that .

The code:

btPlay.setOnClickListener(v -> {

        chronometer.setBase(SystemClock.elapsedRealtime());
        chronometer.start();

    });
Diligent PD
  • 101
  • 8

2 Answers2

1
btPlay.setOnClickListener(v -> {

      startCounting=true;

    });

myHandle = new Handler();
 myHandle.post(new Runnable() {

     @Override
     public void run() {
        myHandle.postDelayed(this, 1000);
        if(startCounting){
           //put your counting code here.
        }
     }

});

the void run function will get called every 1 second. you can add you code inside the run method.

0

Are you working on Android?. If so, then you can try using the handler class to run repeated tasks.