Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. Threading and Asynchronous Processing > Understanding StrictMode

Understanding StrictMode

Strict mode is a method developers can use to detect operations that should not be performed on the main thread. Beginning in API Level 9, developers can enable strict mode in their own applications to detect when they were, for instance, performing network or disk operations on the main thread. In API Level 11, strict mode was expanded with system-wide settings. These settings disallow some operations on the main thread and instead throw exceptions. To enable strict mode in your own applications to behave like API Level 11 or later, use the following code:

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
        .detectAll().penaltyDeath().build();

StrictMode.setThreadPolicy(policy);


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint