Android chronometer

How do I start the chronometer with a specific time other than the default 00:00? Can chronometerObj.setBase (startTime) be set?

ch.setBase(SystemClock.elapsedRealtime()-anylongvalue); ch.start();

Can I set the start time if I put anylongvalue?

+3


source to share


2 answers


Generally:



mChronometer.setBase (SystemClock.elapsedRealtime () - (nr_of_min * 60000 + nr_of_sec * 1000)))

0


source


The chronometer object, when instantiated, defaults to the base time currently set ('now', as in the value you get from SystemClock.elapsedRealtime()

).

You can change the base time (00:00) by calling setBase(<some other value>)

.

Presumably, although I haven't tried the experiment, you could see the elapsed time since the last boot of the system with setBase(0)

.



So, you can use the chronometer to see the elapsed time from any random call you have made in the past to SystemClock.elapsedRealtime()

. The trick is that you need to store this value somewhere, you can reliably get it back despite changes in the state of the app and phone. (See. All Android: chronometer as a regular stopwatch How to set start time, for example, a chronometer "Base".?? .

Many of the responses indicate that they persist at arbitrary times in the past. but, at best, it only keeps the timer counting down while the phone stays on.

I am already using a database and storing the start time there. I created a table with one column for it and saved one record in it. My chronometer time was saved when I rebooted my phone.

0


source







All Articles