0

I am working on a simple Chronometer app and I was wondering how to check if a chronometer is running. For example I have the below method to start the Chronometer but if pressed I want it to check to see if it is already running and if it is to display a warning. I know I would use an IF statement but I am not sure how to check to see if the chronometer is running. Any help is appreciated.

I now have the below code. It starts the chronometer but if its already running the button just resets it instead of stopping it.

boolean crun = false;

    if(crun = true){
     chronometer.setBase(SystemClock.elapsedRealtime());
     chronometer.start();
     crun = true;
     Vibrator vib = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    vib.vibrate(100);}

    else  {
          chronometer.stop();
          crun  = false;
        }
steelthunder
  • 438
  • 2
  • 12
  • 27

1 Answers1

2

You can try sumthing like this.But its not a perfect solution.

boolean isChronometerRunnig = false;
if(true)  // condition on which you check wheater start or stop
{
    chronometer.start();
    isChronometerRunnig  = true;
}
else
{
  chronometer.stop();
  isChronometerRunnig  = false;
}
Harshal Benake
  • 2,391
  • 1
  • 23
  • 40