Is there any way to set time out in android, if there is no response from server for specific period.
Asked
Active
Viewed 1,627 times
2 Answers
1
Following is code that i used for time out
uri = new URI(url);
HttpGet method = new HttpGet(uri);
method.addHeader("Content-Type", "application/json");
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 60000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 65000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(method);
HttpEntity responseEntity = response.getEntity();
statuscode = response.getStatusLine().getStatusCode();
Put this in a try catch block and if exceeds the time it will throw the exception

Labeeb Panampullan
- 34,521
- 28
- 94
- 112
-
pls check following link: http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java – Zoombie Feb 21 '11 at 11:52
0
Try checking the coonectivity to the url first before seeking data reply

Rohit Sharma
- 13,787
- 8
- 57
- 72
-
Yes i have done checking with getNetWorkInfo().isConnectedOrConnecting() – Zoombie Nov 25 '10 at 09:11