title: Slow Internet connection leads to force close
body: <p>I am developing an android application where in each activity i need to pass some data onto the server and get back the responses before going to the next activity. The application works fine if the internet is fast enough. But as the speed goes down the application force closes. How to deal with slow internet connection so that it might not lead to force close of application?????</p>
  
  <p>Here is some part of code</p>
  
  <pre><code>public void onClick(View v) {
      // TODO Auto-generated method stub
      UserFunctions userFunction = new UserFunctions();
      if(userFunction.isNetworkAvailable(getApplicationContext()))
      {
          answer="";
          for(int check1=0;check1&lt;counter2;check1++){
              int check2=0;
              answer=answer+option4[check1]+"|";
              while(check2&lt;counter1){
                  if(edTxt[check1][check2].getText().toString().equals("")){
                      answer="";
                      break;
                  }
                  else{
                      answer=answer+edTxt[check1][check2].getText().toString()+"|";
                  }
                  check2++;       
              }   
              if(answer.equals("")){
                  break;
              }
              else{
                  answer=answer+"||";
              }
          }
          if(answer.equals("")){
              Toast.makeText(this, "Please fill all fields", 600).show();
          }
          else{
          userFunction.form1(surveyId,userId , quesNo, answer);
          if(total&gt;0){
              draw(temp); 
          }
          else{
              ques_no++;
              ArrayList&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();  
              params.add(new BasicNameValuePair("quesNo", Integer.toString(ques_no)));
              params.add(new BasicNameValuePair("surveyId", surveyId));
              count = getJsonFromURL22(surveyCond, params);           
              j=Integer.parseInt(result);
              if(j==22)
              {
                  Toast.makeText(this, "Survey Completed", 600).show();
                  Intent home=new Intent(Format16.this, SurveyCompleted.class);
                  UserFunctions userFunctions = new UserFunctions();
                  userFunctions.full(surveyId);
                  Bundle d=new Bundle();
                  d.putString("userId", userId);
                  home.putExtras(d);
                  startActivity(home);
              }
       public String getJsonFromURL22(String url, List&lt;NameValuePair&gt; params){
  try{
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(url);
      httppost.setEntity(new UrlEncodedFormEntity(params));
      HttpResponse response = httpclient.execute(httppost);
      HttpEntity entity = response.getEntity();
      is = entity.getContent();
  }catch(Exception e){
      Log.e("log_tag", "Error in http connection"+e.toString());
  }
  //convert response to string
  try{
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
      sb = new StringBuilder();
      sb.append(reader.readLine());
  
      String line="0";
      while ((line = reader.readLine()) != null) {
          sb.append(line);
      }
      is.close();
      result=sb.toString();
  }catch(Exception e){
      Log.e("log_tag", "Error converting result "+e.toString());
  }
  return result;
  }
  </code></pre>