Android: Doing networking on another thread

Posted on under English, Android, Tutorials

Beware! This post is more than 3 years old, it may be outdated or incorrect! Please check elsewhere for accurate information!

Since Honeycomb (3.x), Google has prevented apps to run networking operations on the main thread, since it would cause the app to freeze while it's waiting for the network operation to finish.

There aren't many easy solutions to understand, and many use tons of code and usually extend the class AsyncTask, which is needless. If you only need to fetch text resources from the Internet, this code below will do.

Basically put your existing code inside the try/catch block and hope it'll work :D


This post was last updated on February 8th, 2014.