Created
August 4, 2024 10:24
-
-
Save mehdiyari/215fce0b15215d811045838315d30d4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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