For the More Curious: StrictMode

There are some things you simply should not do in your Android app – mistakes that lead directly to crashes and security holes. For example, executing a network request on the main thread would probably result in an ANR error in poor network conditions.

Instead of Android happily allowing you to invoke a network request on the application’s main thread, you get a NetworkOnMainThread exception and log message instead. This is because of StrictMode, which noticed your mistake and helpfully let you know about it. StrictMode was introduced to help you detect this and many other programming mistakes and security problems in your code.

Without any configuration, networking on the main thread is guarded ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.