StrictMode
严苛模式,Android 提供的一种运行时检测机制
检测两大策略:线程策略,虚拟机策略
官方地址:https://developer.android.com/reference/android/os/StrictMode
注意:如需启用严苛模式需尽早启动来使其生效
线程策略
1 2 3 4 5 6 7 8 9 10 11 12 13
| StrictMode.setThreadPolicy( ThreadPolicy.Builder() .detectCustomSlowCalls() .detectResourceMismatches() .detectUnbufferedIo() .detectDiskReads() .detectDiskWrites() .detectNetwork() .penaltyLog() .penaltyDeath() .penaltyDialog() .build() )
|
虚拟机策略
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| StrictMode.setVmPolicy( VmPolicy.Builder() .setClassInstanceLimit() .detectUntaggedSockets() .detectCleartextNetwork() .detectActivityLeaks() .detectContentUriWithoutPermission() .detectCredentialProtectedWhileLocked() .detectFileUriExposure() .detectImplicitDirectBoot() .detectLeakedClosableObjects() .detectLeakedRegistrationObjects() .detectLeakedSqlLiteObjects() .detectNonSdkApiUsage() .penaltyLog() .penaltyDeath() .build() )
|