StrictMode

Performance Junior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Fill the blank

Turn on main-thread checks in debug builds.

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        if (BuildConfig.DEBUG) {
            StrictMode.setThreadPolicy(
                StrictMode.ThreadPolicy.Builder().____().penaltyLog().build()
            )
        }
    }
}
Options
Hint 1 of 1

Which call turns on detection?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A detectAll

Correct. It detects disk, network and other main-thread violations.

Why not the others?
  • B permitAll. That allows everything.
  • C detectLeakedClosableObjects. That's a VM policy check.
  • D penaltyDeath. That's a penalty, not a detection.

30-second answer

StrictMode is a developer tool that detects mistakes as they happen: disk reads and writes or network on the main thread (thread policy), and leaked closeables, Activities and unsafe intents (VM policy). Turn it on in debug builds at startup with penaltyLog() or penaltyDeath() so problems show up before users hit them.

Practise saying it · 25 s. No recording, just a timer

Explain StrictMode.

Say your answer out loud, then check which of these points you covered:

  • Thread policy: disk and network on main
  • VM policy: leaks and unsafe intents
  • Debug builds only
  • Fix violations

Deep dive

detectAll() picks up new checks as Android adds them.

Some libraries trigger violations; use permitDiskReads locally only with a reason.

detectUnsafeIntentLaunch catches intents relaunched from untrusted sources.

Never enable penaltyDeath in release builds.

Common mistakes

  • Enabling StrictMode in release builds.
  • Ignoring violations because 'it's only debug'.
  • Suppressing violations globally.

Senior take & follow-ups

Explain the two policies and show how you enable it in debug only.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does the VM policy catch?

    Show hint

    Leaked closeables, leaked Activities, unsafe intents, cleartext traffic and more.

  2. Why penaltyDeath in debug?

    Show hint

    Crashing makes violations impossible to ignore.

Suggest a fix if something here is wrong or out of date.