Predict the output
A tap handler runs for 300 ms on the main thread at 60 Hz. About how many frames are dropped?
button.setOnClickListener {
val start = System.nanoTime()
while (System.nanoTime() - start < 300_000_000L) { /* busy */ }
}Hint 1 of 1
How long is one frame at 60 Hz?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A About 17
Correct. 300 ms spans about 18 frame slots of 16.7 ms. The frame that finally draws uses one, so about 17 are skipped.
Why not the others?
- B 1. Every frame due during those 300 ms is missed, not just one.
- C 0, drawing happens on the RenderThread. The RenderThread needs the main thread to produce each frame's display list first.
- D 300. Frames come every 16.7 ms, not every millisecond.
Illustrative, based on Compose and Android rules; not a device recording
Text version
| Frame | Work (ms) | Result |
|---|---|---|
| F1 | 7 | on time |
| F2 | 9 | on time |
| F3 | 6 | on time |
| F4 | 8 | on time |
| F5 | 7 | on time |
| F6 | 9 | on time |
0 dropped frames at 60 Hz (16.7 ms budget); ANR dialog at 5 s: no.
| Frame | Work (ms) | Result |
|---|---|---|
| F1 | 7 | on time |
| F2 | 300 | ⏱ late (the next 17 dropped) |
| F3 | – | ✕ dropped (F2 still running) |
| F4 | – | ✕ dropped (F2 still running) |
| F5 | – | ✕ dropped (F2 still running) |
| F6 | – | ✕ dropped (F2 still running) |
| F7–F19 | – | ✕ dropped ×13 (F2 still running) |
17 dropped frames at 60 Hz (16.7 ms budget); ANR dialog at 5 s: no.