0

I am using Async class lik below but i don't have any Idea How can set Time out in Async class

Some time internet connection is slow then Async class take much time

private class GetServerChallans extends AsyncTask<String, Void, String> {
         @Override
            protected String doInBackground(String... urls) {
              String response = "";
              HttpEntity resEntity;
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("wwww...........");

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("token",strtoken));
                    nameValuePairs.add(new BasicNameValuePair("customer_code",strcustomer_code));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    // Execute HTTP Post Request
                    HttpResponse responsePOST = httpclient.execute(httppost);
                     resEntity = responsePOST.getEntity();
                     response=EntityUtils.toString(resEntity);
                } catch (Exception e) {
                  e.printStackTrace();
                }

              return response;
            }

            @SuppressLint("DefaultLocale")
            @Override
            protected void onPostExecute(String result) {
                pd.dismiss();
                if(result!=null)
                {

                }

                }
            }

            @Override
            protected  void onPreExecute()
            {
                //pd = ProgressDialog.show(MyProfile.this, "","Please wait...");

            }
          }

Please Help Me how i can use time out in Async class

Thanks In Advance

user3722005
  • 63
  • 1
  • 5

1 Answers1

0
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
orenk86
  • 720
  • 9
  • 24