Android Programming: The Big Nerd Ranch Guide, Third Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano
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 will 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 against. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access