2

Is there any way to set time out in android, if there is no response from server for specific period.

Zoombie
  • 3,590
  • 5
  • 33
  • 40

2 Answers2

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