1. Strict Mode (Development)
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build()
)
2. ANR Detection
/data/anr/traces.txt3. Using Choreographer
Choreographer.getInstance().postFrameCallback { frameTimeNanos ->
val jank = (System.nanoTime() - frameTimeNanos) / 1_000_000
if (jank > 16) Log.w("Jank", "Frame took $jank ms")
}
4. Profiler Tools
Key Signs of UI Thread Blocking:
Mark this when you can explain the answer in your own words.
Help fellow developers prepare for interviews
Sharing helps the Android community grow ๐