android6-6 Exercise 1: StrictMode ============================== // NotesApplication.onCreate(): catch accidental main-thread work and leaks in DEBUG builds only if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() // docs suggest a crashing penalty so violations are hard to miss .build() ) StrictMode.setVmPolicy( StrictMode.VmPolicy.Builder() .detectActivityLeaks() .detectLeakedClosableObjects() .detectLeakedRegistrationObjects() .detectLeakedSqlLiteObjects() .penaltyLog() .build() ) } // Main-safe by construction (Architecture & Data 3): the repository switches threads itself class DefaultNotesRepository( private val dao: NoteDao, private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO ) { suspend fun exportAll(): String = withContext(ioDispatcher) { // heavy file/JSON work: never on the main thread buildExportText(dao.getAll()) } } Run the app in debug and use every screen; filter Logcat by "StrictMode". Typical findings (general knowledge, do not assume): disk reads or writes on the main thread (for example reading a preference or file in onCreate), leaked closable objects. For each violation report the stack's first line from your code, say what it is, and fix one by moving the work off the main thread (withContext(Dispatchers.IO) or a suspend DAO call). Report what you actually saw. Code unrun.