title: Check if AsyncTask is taking too long
body: <p>I have an AsyncTask that get info from the web. Sometimes the connection fails  and the AsyncTask processdialog is running forever.</p>
  
  <p>In the doInBackground I have a check in the end if my catched info are empty and if this is the case, it should appear Positive button/Negative button, but this is not happening. The dialog is just running.</p>
  
  <p>How can I check if an AsyncTask is taking too long time (Maybe 5 seconds) and dismiss the dialog?</p>
  
  <p>Code snippet (doInBackground): </p>
  
  <pre><code> //orders is my ArrayList&lt;Order&gt; object, from my own Order class.
   if(orders==null) {
                  pdia.dismiss();
                  AlertDialog.Builder alt_bld = new AlertDialog.Builder(ctx);
                  alt_bld.setMessage("Try agin?")
                  .setCancelable(false)
                  .setPositiveButton("Try again", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
  
                      button_refresh.setVisibility(View.GONE);
  
                       new ListTask().execute(null, null , null);
  
  
                  }
                  })
                  .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                  dialog.cancel();
                  }
  
                  });
                  AlertDialog alert = alt_bld.create();
                  alert.setTitle("Connection failed!");
                  alert.show();
              }
              else {
                  return orders;
              }
  </code></pre>
  
  <p>Thanks in advance and tell me if you need more info!</p>