I'm using chronometer to display the time in my android application.
i want to get the chronometer value that is displayed in the screen. i tried to use
int stoppedMilliseconds = 0;
String chronoText = chronometer.getText().toString();
String array[] = chronoText.split(":");
if (array.length == 2) {
stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 1000
+ Integer.parseInt(array[1]) * 1000;
} else if (array.length == 3) {
stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 60 * 1000
+ Integer.parseInt(array[1]) * 60 * 1000
+ Integer.parseInt(array[2]) * 1000;
}
chronometer.setBase(SystemClock.elapsedRealtime() - stoppedMilliseconds);
and to get the value i used long elapsedMillis = SystemClock.elapsedRealtime() - chronometer.getBase();
it displays a certain number like that for me it does not look like the time that is displayed on the screen. if the timer on the screen shows 1 sec, i want to get the value exact 1sec and not any random numbers.
is there anyone that can help me with this?