AndroidHttpClient versus HttpUrlConnection for API Level 9 and above
Asked Answered
S

1

12

Which is better for API Level 9(Gingerbread) and why? Is there any benefit to use AndroidHttpClient over HttpUrlConnection?

Any help or guidance will be well appreciated.

Shovelboard answered 28/2, 2014 at 12:54 Comment(1)
Please describe what you want to do. Download images? Synchronize data with your server? What kind of data do you send/receive? How many roundtrips will you have? Is data easily compressable? Are you send/receive data in a background service or in an Activity while user is waiting for it? What if user switches to another Activity? Throw away/cancel request or store the result for later use? If you like, you can edit your question (better readable for all of us).Faulkner
F
15

Google doesn't recommend using AndroidHttpClient, only on very old Android versions.

But as you can see in many questions on SO, HttpURLConnection is not easy to use. It's very low-level and doesn't have a comfortable interface. You have to know quite a lot how it's working internally and if you have luck, you get exceptions when you use it the wrong way.

For that reason many libraries have been developed for Android developers. You can find a list (and a concrete implementation BTW) at DavidWebb. There are low-level libraries and some very powerful which take the burden of background processing from you.

Edit

Q: Is there any benefit to use AndroidHttpClient?

A: From programming point of view, AndroidHttpClient is much easier to use. But as Google says, due to difficulties with backward compatibility, they cannot improve this class and instead put all efforts in improving HUC (abbr. for HttpURLConnection). For me this reads like "we will let AndroidHttpClient die". Of course this class will be present in all future versions of Android SDK I suppose, but HUC does many intelligent things under the hood, e.g. transparent download compression.

tl;dr I wouldn't use AndroidHttpClient for current app development.

Faulkner answered 28/2, 2014 at 13:37 Comment(2)
Hi hgoebl, thanks for the quick reply. Is there any benefit/advantage of using AndroidHttpClient?Shovelboard
As of v23, AndroidHttpClient is not available except through external libraries.Muzhik

© 2022 - 2024 — McMap. All rights reserved.