title: Stop a thread if dont receive any response in Android?
body: <p>i have a progressDialog and i connect to a webservice. While i dont receive the response, i show the progressDialog but if i dont receive nothing, the progressDialog dont close.</p>
  
  <pre><code>progressDialog = ProgressDialog.show(ProfilesMenu.this, "", Utils.CONTACT_WEBSERVICE, true);
  Thread thread = new Thread(ProfilesMenu.this);
  thread.start();
  
  @Override
  public void run() {
      linkToWebService = new Utils();
      T_VERSION version = new T_VERSION(Utils.MTA, Utils.STA);
      try {
          // é envio o nº de tlm do item selecionado para verificar o seu status
          Vector&lt;T_COMMAND_OUT&gt; command =  linkToWebService.getCardInfoDemand(version, "0", 
                  profilesArrayList.get(menuInfoPosition).getPhoneNumber());
  
          responseWebservice = command.get(0);
          handler.sendEmptyMessage(0);
      } catch(Exception e) {
  
      }
  }
  
  private Handler handler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
          progressDialog.dismiss();
  
          if(responseWebservice.getid()==Utils.CARD_INFO_RESPONSE_ID){
              if(responseWebservice.getLocked().equals(Utils.UNLOCKED)){
  
                  profilesArrayList.get(menuInfoPosition).setCalypsoNumber(responseWebservice.getCalypsoNumber());
                  Log.d("calypsoNumber", profilesArrayList.get(menuInfoPosition).getCalypsoNumber());
                  if(profilesArrayList.get(menuInfoPosition).getCalypsoNumber()!="")
                      profilesArrayList.get(menuInfoPosition).setState(true);
                  SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_PROFILES_NAME+getProfilesCounter(), MODE_PRIVATE);
                  SharedPreferences.Editor prefEdit = preferences.edit();
                  prefEdit.putString(CALYPSO_NUMBER, profilesArrayList.get(menuInfoPosition).getCalypsoNumber());
                  prefEdit.commit();
  
                  createAlertDialog("Status of Profile", "This phone number is unlocked!").setIcon(R.drawable.right_icon).show();
              }else if (responseWebservice.getLocked().equals(Utils.LOCKED)) {
                  createAlertDialog("Status of Profile", "This phone number is locked! You have to active it " +
                  "for buy tickets").setIcon(R.drawable.wrong_icon).show();
              }
          } else if(responseWebservice.getid()==Utils.ERROR_MESSAGE_ID){
              createAlertDialog(responseWebservice.getPage().getTemplateRef(), "Data not recognized by webservice.").setIcon(R.drawable.wrong_icon).show();
          }
      }
  };
  </code></pre>
  
  <p>I try to stop thread with the .sleep but didn't work. How i can stop thread if i dont receive nothing in the ruin() ?? thanks</p>