2

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

Zoombie
  • 3,480
  • 4
  • 31
  • 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
  • 33,641
  • 28
  • 92
  • 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,527
  • 7
  • 56
  • 70