Android chronometer
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.
source to share