Friday, June 19, 2015

Android HTTP clients

Android HTTP clients:
Most network-connected Android apps use HTTP to send and receive data. Android includes two HTTP clients HttpURLConnection and Apache HttpClient.


1.Apache HTTPClient:
DefaultHttpClient and its sibling AndroidHttpClient are extensible HTTP clients suitable for web browsers. They have large and flexible APIs. Their implementation is stable and they have few bugs.
But the large size of this API makes it difficult for us to improve it without breaking compatibility. The Android team is not actively working on Apache HTTP Client.
2.HttpURLConnection:
HttpURLConnection is a general-purpose, lightweight HTTP client suitable for most applications. This class has humble beginnings, but it's focused API has made it easy for us to improve steadily.
Prior to Froyo, HttpURLConnection had some frustrating bugs. In particular, calling close() on a readable InputStream could poison the connection pool. Work around this by disabling connection pooling.

Perform Network Operations on a Separate Thread:
Network operations can involve unpredictable delays. To prevent this from causing a poor user experience, always perform network operations on a separate thread from the UI. The AsyncTask class provides one of the simplest ways to fire off a new task from the UI thread. So android clients should use AsyncTask for network operations.

No comments:

Post a Comment