title: Show AlertDialog depending on how AsyncTask.execute() runs in the same code block
body: <p>I'm writing a function which executes Http request (with the help of HttpPost, HttpClient and AsyncTask) and shows AlertDialog if <code>HttpClient.execute()</code>(which runs in <code>AsyncTask.doInBackground()</code>) takes too much time.</p>
  
  <p>The problem is that I should wait for some time after <code>AsyncTask.execute()</code> is called, before showing the message. But if I use <code>AsyncTask.get()</code> to prevent my function from finish, nothing can be changed in the UI until AsyncTask is finished.
  Here is the code example:</p>
  
  <pre><code>{
      HttpClient mHttpClient;
      HttpPost mHttpPostAuth;
  
      public Boolean openConnection()
      {
          //Checking if HttpClient.execute() is finished within 300 milliseconds
          //howing the message if not
          mScheduledThreadPoolExecutor.schedule(new Runnable(){
              public void run(){
                  context.runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          if(!mResponseReceived){
                              try{
                                  mWaitingForResposeAlert = mWaitingForResposeBuilder.show();
                              }
                          }
                      }
                  });
              }
          }, 300, TimeUnit.MILLISECONDS);
  
          try{
              new AsyncTask&lt;Void, Void, HttpResponse&gt;(){
                  @Override
                  protected HttpResponse doInBackground(Void... params){
                      try {                       
                          mResponseReceived = false;
                          HttpResponse response = mHttpClient.execute(mHttpPostAuth);
                          mResponseReceived = true;
                          return response;
                      }
                      catch (Exception e){
                      }
  
                      mResponseReceived = true;
                      return null;
                  }
  
                  protected void onPostExecute(HttpResponse response){
                      try{
                          if (response == null) return;
                          switch (response.getStatusLine().getStatusCode()){
                              case HttpStatus.SC_OK:{
                                  //Reading the response
                                  break;
                              }
                              default:{
                                  break;
                              }
                          }
                      }
                      catch(Exception e){
                      }
                  }
              }.execute().get();
  
          if(mWaitingForResposeAlert != null) mWaitingForResposeAlert.dismiss();
  
          return !(sid==null);
      }
  }
  </code></pre>
  
  <p>Is there any way to show AlertDialog depending on how <code>AsyncTask.execute()</code> runs in the same code block?</p>