Android

Strict Mode Policy : A tool to catch the bug in the Compile Time.

Introduction#

Strict Mode is a special class introduced in Android 2.3 for debugging. This developer tools detect things done accidentally and bring them to our attention so that we can fix them. It is most commonly used to catch the accidental disk or network access on the applications’ main thread, where UI operations are received and animations takes place. StrictMode is basically a tool to catch the bug in the Compile Time mode.

Remarks#

StrictMode is basically a tool to catch the bug in the Compile Time mode. Using this we can avoid the memory leaks in our applications.

The below Code Snippet is to setup the StrictMode for Thread Policies. This Code is to be set at the entry points to our application.

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()  
    .detectDiskWrites()  
    .penaltyLog() //Logs a message to LogCat  
    .build())

The below code deals with leaks of memory, like it detects when in SQLLite finalize is called or not.

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()  
    .detectActivityLeaks()  
    .detectLeakedClosableObjects()  
    .penaltyLog()  
    .build()); 

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow