In testing an app, I keep getting errors that occur sporadically on only one device: the GT-I9100 (European) Samsung Galaxy S II. These errors do not occur on any other device, not even the SPH-D710 (Sprint) Samsung Galaxy S II.
The URLs used by the app do not change. They are the same that I can type into a web browser, or that the iOS and desktop versions of the app use. But sometimes they throw an UnknownHostException, and sometimes they don’t.
Here is a heavily sanitized version of the code I am using:
AndroidHttpClient client = AndroidHttpClient.newInstance(activity.getString(R.string.user_agent));
HttpPost httpPost = new HttpPost("http://" + subdomainId + ".website.com/doSomething.aspx");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("parameter1", value1));
nameValuePairs.add(new BasicNameValuePair("parameter2", value2));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpContext httpContext = new BasicHttpContext();
HttpResponse response = client.execute(httpPost, httpContext);
... ...
Is there any quirk of the Samsung Galaxy S II that could be causing this? It’s running Android 2.3.6.
As others said it could be caused by a non-existent internet connection.
Maybe try adding a request retry handler like so..
That way if the internet goes off for a split second you the httpclient can handle it. Here apache also suggest retrying if you have any transport errors
So I would suggest it is good practice to use the retry handler anyway