The penalty is death – StrictMode in Android

Within Android development you should avoid performing long running operations on the UI thread. This includes file and network access.

But sometimes it is difficult to remember to make all the right things in your application during development. That is were StrictMode comes in. It allows to setup policies in your application to avoid doing incorrect things. For example the following setup will crash your application if it violates some of the Android policies. StrictMode should only be used during development and not in your live application.

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
	.detectAll().penaltyLog().penaltyDeath().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
	.penaltyLog().penaltyDeath().build());

For an introduction to background processing in Android see Android Background Processing Tutorial. More information about StrictMode can be found here.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Android. Bookmark the permalink.