title: AsyncTask doInBackground will not finish/hangs
body: <p>I've got a AsyncTask that will not finish when I have my <code>lib.roomAvailable()</code> call in the doInBackground method. When QueueTask is called a progressDialog will show and
  it sticks. It should go away after 5 seconds.</p>
  
  <p>If I remove <code>lib.roomAvailable()</code> from the doInBackground method everything work as expected. Why do I get this strange behaviour when I call <code>lib.roomAvailable()</code>?</p>
  
  <p><code>roomAvailable()</code> calls another AsyncTask can this be an issue?</p>
  
  <pre><code>    public class QueueTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
      private ProgressDialog progressDialog;
      private Library lib;
      private String date;
      private int room;
      private int time;
      private String user;
      private String id;
  
      public QueueTask(String date, int room, int time, String user, String id) {
          this.date = date;
          this.room = room;
          this.time = time;
          this.user = user;
          this.id = id;
      }
  
  
      @Override
      protected void onPreExecute() {
          lib = new Library();
          progressDialog = ProgressDialog.show(ManageRoomActivity.this, "Queuing", "Queuing process", true);
      }
  
      @Override
      protected Void doInBackground(Void... params) {
  
              int timer = 5;
              while(timer &gt; 0) {
                  if(lib.roomAvailable(date, room, time)) {
                                  Log.w("RoomAvailable", "Room Available");
                              }
                  android.os.SystemClock.sleep(1000);
                  timer --;
                  Log.w("TIMER", "" + timer);
              }
              progressDialog.dismiss();
                  return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
          progressDialog.dismiss();
          Intent intent = new Intent(ManageRoomActivity.this, DatePickerActivity.class);
          ManageRoomActivity.this.startActivity(intent);
      }
  }
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <pre><code>public boolean roomAvailable(String date, int room, int time) {
            boolean available = false;
  
            String timeString = "";
            if(time &lt; 10)
                timeString = "0";
            timeString = timeString + time;
  
            String roomNum = "";
            if(room &lt; 10) 
                roomNum = "0";  
  
            roomNum = roomNum + room;
            AsyncTask&lt;String, Void, String&gt; readSource = new URL_Source();
            String source = "";
          try {
              String uri = getURI(date);
              source = readSource.execute(getURI(date)).get();
              String[] chunks =  source.split("&lt;td");
                for(String chunk:chunks) {
                    if(chunk.contains(date) &amp; chunk.contains("=Grp" + roomNum) &amp; chunk.contains("stid=" + timeString))
                        available = true;
                }
                return available;
          } catch (InterruptedException e) {
              e.printStackTrace();
          } catch (ExecutionException e) {
              e.printStackTrace();
          }
          return available;
        }
  </code></pre>
  
  <p>The other AsyncTask:</p>
  
  <pre><code>public final class URL_Source extends AsyncTask&lt;String, Void, String&gt; {
  
  public URL_Source() {
  
  }
  
  protected String doInBackground(String... uri) {
      try {
          URL url = new URL(uri[0]);
          InputStream in = url.openStream();
          StringBuilder source = new StringBuilder();
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  
          String line;
          while((line = reader.readLine()) != null) {
              source.append(line);
          }
          in.close();
          return source.toString();
  
  
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return "ERROR";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Solution:</p>
  
  <p>I didn't have a clue how AsyncTask worked. You cannot call a AsynchTask within a AsyncTask!</p>