H
H
Helig2018-08-12 21:47:14
Java
Helig, 2018-08-12 21:47:14

How to stop the chronometer?

The problem is that the timer, reaching 00:00, continues to decrease and does not stop, it goes to -00:01.
I am using the built in Chronometer.
Here is the code:

private long flagToChr = 0;
private Chronometer mChronometer;
private long lastPause = 0;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mChronometer = (Chronometer) findViewById(R.id.chronometer);
        mChronometer.setBase(SystemClock.elapsedRealtime());
        mChronometer.setCountDown(true);
}

   public void buttonStartChronometer(View view){

        if (lastPause == 0){
            mChronometer.setBase(SystemClock.elapsedRealtime() + flagToChr);
            mChronometer.start();
        }else{
            mChronometer.setBase(mChronometer.getBase() + SystemClock.elapsedRealtime() - lastPause);
            mChronometer.start();
        }


    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question