0

Good Morning!

I´m trying to create a chronometer that works, when the condition in the parethesis is true, the 'stopwatch' started to count.. if the condition is false, only the textview is paused, it's not resuming, because it still running in background.. I need it to be resumed at where I've stopped..Thanks!!

here's my dot java code :

if (Normaaa>decibelio){

        crono.start();//empieza el CRONOMETRO

    }  

    if (Normaaa<=decibelio){




    crono.stop();

}
}  

1 Answers1

0

You need to define a variable wich contains the time when chronometer stops:

Long timeRunning = 0;

if (Normaaa<=decibelio){
   timeRunning = SystemClock.elapsedRealTime() - chrono.getBase();
   crono.stop();
}

You will use it when you resume your chrono, for example with this function:

void resumeChrono(){
    crono.setBase(SystemClock.elapsedRealTime() - timeRunning);
    crono.start();
}

If you want to completly reset your crono and start counting:

void restartCrono(){
   crono.setBase(SystemClock.elapsedRealTime());
   crono.start();
}
Exynus
  • 101
  • 2
  • 3