1

I've been looking how to create a simple timer in Android but mostly what I found were Countdown and using Timer for delayed events. I don't feel they're suitable for my case.

What I want to do is I want to start a timer from 0 when I start a method (this timer should be a variable). I will put this timer in a "while" loop so it will keep increasing. Then, I have a list of array with numbers (they are time points in either millisecond or second), for example (in second), [10, 15, 20] so they're tenth second, fifteenth second, and twentieth second. Btw, the comparison start from the first array and continues to the next position when a number match, I guess I can call it progressive comparison?

Next thing is I want to compare the "timer" variable ,which is keep increasing, with the numbers in the array. If the numbers match, let's say, a text will be shown. I don't know if this is possible though...

If there's any solution or alternatives for my case, please share them, thanks =)

Steven Pongidin
  • 153
  • 1
  • 11

1 Answers1

0

Easiest way: Playing with System.currentTimeMillis(), so:

// Here I start the timer.
t0=System.currentTimeMillis();

"while loop"
{
t=System.currentTimeMillis()-t0; // There you have the elapsed time

If (t==10) then bla
If (t==15) then blabla
If (t==20) then blablabla
(...)
}

I had the same question it was solved like this. You can see it here too: Android: Chronometer with Milliseconds?

Community
  • 1
  • 1
ArcDare
  • 3,106
  • 4
  • 27
  • 38