Android: Set HTTP socket timeout

The default timeout value for a HTTP request is quite long. So long that you'd forget what you were doing and wonder why the game has crashed.

Reduce the timeout value to get more responsiveness out of your app.

HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); // Connection timeout
HttpConnectionParams.setSoTimeout(httpParameters, 3000); // Socket timeout

// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient(httpParameters);

Now you can use the HttpClient as per usual for GET or POST requests.

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog