StrictMode – Detects things you might be doing by accident

Useful diagnostic tool. It helps to find and fix performance issues, object leaks and other runtime issues.

if (BuildConfig.DEBUG) {
 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
       .detectAll()
       .penaltyLog()
       .build());
 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
       .detectAll()
       .penaltyLog()
       .penaltyDeathOnNetwork()
       .build());
}

Example in logs:

D: StrictMode policy violation; ~duration=19 ms: 
        android.os.StrictMode$StrictModeDiskReadViolation: 
                policy=543 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at android.app.SharedPreferencesImpl.awaitLoadedLocked(SharedPreferencesImpl.java:202)
at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:259)
at .MyApplication.notificationToggleCheck(MyApplication.java:54)
at .MyApplication.onCreate(MyApplication.java:35)
...

http://developer.android.com/reference/android/os/StrictMode.html


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.