Application
, Activity
, or other application component's onCreate()
method:
if (BuildConfig.SHOW_LOG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
penaltyDeath()
: Crash the whole process on violation.
penaltyDeathOnNetwork()
: Crash the whole process on any network usage.
penaltyDialog()
: Show an annoying dialog to the developer on detected violations.
penaltyFlashScreen()
: Flash the screen during a violation.
penaltyLog()
: Log detected violations to the system log.