Skip to content

Instantly share code, notes, and snippets.

@mehdiyari
Created August 4, 2024 10:24
Show Gist options
  • Save mehdiyari/215fce0b15215d811045838315d30d4d to your computer and use it in GitHub Desktop.
Save mehdiyari/215fce0b15215d811045838315d30d4d to your computer and use it in GitHub Desktop.
class Application : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
applyStrictMode()
}
}
private fun applyStrictMode() {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectNetwork() // Detect network operations on the main thread.
.detectDiskReads() // Detect disk read operations on the main thread.
.detectDiskWrites() // Detect disk write operations on the main thread.
.detectExplicitGc() // API 34+: Detect explicit garbage collection calls on the main thread.
.detectCustomSlowCalls() // Detect custom slow operations on the main thread.
.detectResourceMismatches() // Detect mismatches between resource types and getter calls.
.detectUnbufferedIo() // API 26+: Detect unbuffered input/output operations.
//.detectAll() // Detect all types of main thread violations.
.penaltyLog() // Log all detected violations in Logcat.
//.penaltyDialog() // Show a dialog when a violation is detected.
.build()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment