Android Best Practices: StrictMode

When developing Android applications that uses network and database access, you need to do performance tuning. This is where StrictMode comes in handy


StrictMode is used to detect memory leaks. It’s has introduced in Gingerbread and can be used as a development tool.

The configuration below was the proposed in the reference documentation:

public void onCreate() {
     if (DEVELOPER_MODE) {
         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                 .detectNetwork()   // or .detectAll() for all detectable problems
         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()

Update If you’re looking on how to get StrictMode working for all Android platform versions, have a look at this article.

Leave a Reply


captcha *

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