Mike Szczys · May 18, 2013 at 10:00 am

HttpClient Tutorial to Upload and Download with Your App

Developers wanting to interact with the Internet need to choose a package to do the heavy lifting for them. A very common route is to use the built-in HttpClient. The documentation is fairly complete, but it’s a daunting to get started if you’ve never used the package before.

Take a look at the HttpClient tutorial that JFrankie recently posted.  I find his presentation very approachable for the beginner, yet he doesn’t hesitate to move on to the more complex subjects. The guide starts off with a few lines of code used to open a connection, and quickly covers the first gotcha. HttpClient shouldn’t be run in the UI thread, as it presents a blocking function (you don’t know how long it’s going to be before the server answers back). Android will throw an error automatically if you try to do this.

He goes on to wrap the code in an AsyncTask class. This lets it run in a separate thread, launching a method when its work is complete. Most likely you’re looking to download something, a topic which is well covered in the guide. JFrankie wraps up the post by explaining the steps necessary to upload using the HTTP multipart request protocol.

He publicized his article in a Reddit thread, where he also participated in a discussion of the memory leak potential of using AsyncTask. It’s some advice you may want to heed as you build your app around the HttpClient.


_________
Want something on the XDA Portal? Send us a tip!
Mario Tomás Serrafero · Feb 28, 2015 at 03:45 pm · no comments

MWC 2015: What Are Your Predictions?

This wonderful Geek-Christmas time of the year is back once more, promising a lot of exciting reveals from big manufacturers such as HTC and Samsung, but also some pretty gems teased by other smaller OEMs. What kind of exciting products will we see? While we've got a lot of leaked information from the highly expected S6 and M9, there is still a lot to learn about both - and about everything else that will be shown. What kind of trends will...

XDA NEWS
Chris Gilliam · Feb 28, 2015 at 03:13 pm · 1 comment

Best Apps To View RAW Images On Android

Last week, I wrote about the best apps to unleash the raw photographic power of your Lollipop smartphone. All four of those cameras generate lossless DNG images with pounds of potential for apps like Photoshop to unlock, but what if you’re looking to edit or view those pics on the go? QuickPic, Google Photos, and the other mainstays treat raw images like they don't exist. This rundown seeks to fill the void and give you full control over your precious pictures....

XDA NEWS
Emil Kako · Feb 28, 2015 at 10:15 am · 1 comment

Which App Is Most Desperately in Need of an Update?

While the majority of the top apps have already incorporated Google's newest design language, there are still very many apps that are in need of some Material Design love. Which apps do you think are most desperately in need of an update?

DISCUSS
Share This