0

I doing some math game, and I have 25 question for user to answer. So, I want to mesaure how much time that user needed for solving that?

So I need something like Timer, stopwatch with ability to pause time when user click on Back button.

I saw few implementations with Chronometer, is that good for this task?

Zookey
  • 2,637
  • 13
  • 46
  • 80

1 Answers1

2

If you are simply looking to figure out how long the user took you don't even need to use a special object honestly.

Just make a long variable and store the startTime from System.getCurrentTimeInMillis();

long startTime = System.currentTimeMillis();
//do problems here
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;

Log.i("TAG", "It took "+ totalTime / 1000 + " seconds to complete the problems");

To do pausing you'll need a long that tracks how long it was paused and subtract that also from the totalTime.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • long pausedTime = System.currentTimeMillis(); long finalTotalTime = endTime - pausedTime; That should work? – Zookey May 14 '13 at 13:42
  • 1
    not exactly like that you'll need a startPause and stopPause that you subtract to get pausedTime. But you have the right idea, just play with it a bit and you'll get it =) – FoamyGuy May 14 '13 at 13:55