MCQs / Computer Science / Lab: Countdown Timer

Lab: Countdown Timer MCQs — Computer Science

11 multiple-choice questions on Lab: Countdown Timer from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

1. String.format(Locale.US, "%02d:%02d", m, s) produces for m = 3, s = 7:

  1. 3:7
  2. 03:07
  3. 0307
  4. 3:07

Answer: B) 03:07

Explanation: %02d pads numbers to two digits.

Discuss this question

2. The lab saves the absolute end time so that:

  1. The timer runs twice as fast
  2. The app can be uninstalled
  3. The remaining time can be recomputed accurately after recreation
  4. The UI changes colour

Answer: C) The remaining time can be recomputed accurately after recreation

Explanation: endTime − currentTime gives the true remaining time.

Discuss this question

3. Why is timer?.cancel() called in onDestroy()?

  1. To restart the timer
  2. To stop the old timer so it does not keep updating a destroyed activity (memory leak)
  3. Because onDestroy requires it
  4. To save battery only on tablets

Answer: B) To stop the old timer so it does not keep updating a destroyed activity (memory leak)

Explanation: Cancelling prevents leaks and duplicate timers after rotation.

Discuss this question

4. Without saving state, rotating the phone during the countdown would:

  1. Recreate the activity and lose the timer's progress
  2. Speed up the timer
  3. Pause the timer automatically
  4. Have no effect

Answer: A) Recreate the activity and lose the timer's progress

Explanation: Rotation destroys the activity and its variables.

Discuss this question

5. CountDownTimer callbacks run on the:

  1. A separate process
  2. GPU
  3. Network thread
  4. Main (UI) thread, so views can be updated directly

Answer: D) Main (UI) thread, so views can be updated directly

Explanation: It posts callbacks to the main thread looper.

Discuss this question

6. A more modern place to keep timer state across rotation is a:

  1. Toast
  2. BroadcastReceiver
  3. strings.xml
  4. ViewModel exposing StateFlow/LiveData

Answer: D) ViewModel exposing StateFlow/LiveData

Explanation: ViewModels survive configuration changes.

Discuss this question

7. Which method is called once when the countdown reaches zero?

  1. onStop()
  2. onFinish()
  3. onComplete()
  4. onTick()

Answer: B) onFinish()

Explanation: onFinish runs when the time is over.

Discuss this question

8. The two constructor parameters of CountDownTimer are:

  1. minutes and seconds
  2. millisInFuture and countDownInterval
  3. context and layout
  4. startTime and endTime as Strings

Answer: B) millisInFuture and countDownInterval

Explanation: It takes the total duration and the tick interval in milliseconds.

Discuss this question

9. Vibrating the phone at the end requires which manifest permission?

  1. WAKELOCK
  2. CALLPHONE
  3. VIBRATE
  4. None

Answer: C) VIBRATE

Explanation: VIBRATE is a normal permission granted at install.

Discuss this question

10. Which method is called every interval while the timer runs?

  1. onUpdate()
  2. run()
  3. onFinish()
  4. onTick(millisUntilFinished)

Answer: D) onTick(millisUntilFinished)

Explanation: onTick receives the remaining milliseconds.

Discuss this question

11. How is "pause" implemented with CountDownTimer?

  1. Call wait()
  2. Call cancel() and store the remaining time; create a new timer with it to resume
  3. Set interval to zero
  4. Call pause()

Answer: B) Call cancel() and store the remaining time; create a new timer with it to resume

Explanation: CountDownTimer has no pause method.

Discuss this question

Practise Lab: Countdown Timer MCQs

More Computer Science chapters