I writing a simple chess clock app based on android.widget.Chronometer. I'm using it with setCountDown(true)
flag and all logic working well. Each Chronometer creating in a separate Fragment
. But sometimes there are some problems with the chronometer initial value. For example, I'm setting the initial value for 20 seconds but in reality I have this:
And on app restarting this distinguishing may be on random clock. I'm setting initial value this way, in my class that extending android.widget.Chronometer
, and mTimeLimit equals 20000 each times:
private void setTimeLimit() {
mStartTime = SystemClock.elapsedRealtime() + mTimeLimit;
setBase(mStartTime);
}
I'm thinking that problem may be in fragment creating time or so on. Who knows what I'm getting wrong?
I'm find a one solution by adding 100 millis on initial value:
mStartTime = SystemClock.elapsedRealtime() + mTimeLimit + 100;
Seems that it solves a problem, but i think it's not a best decision, maybe somebody knows better approach.