title: Android AsyncTask threads limits?
body: <p>I am developing an application where I need to update some info every time user logs in to the system, I also use database in the phone. For all those operations (updates, retrieving data from db and etc.) I use async tasks. As up till now I didn't see why I shouldn't use them, but recently I experienced that if I do some operations some of my async tasks simply stop on pre-execute and don't jump to doInBackground. That was just too strange to leave it like that, so I developed another simple application just to check whats wrong. And strange enough, I get the same behavior when count of total async tasks reach 5, the 6th one stops on pre-execute.</p>
  
  <p>Does android have a limit of asyncTasks on Activity/App? Or is it just some bug and it should be reported? Did anyone experience the same problem and maybe found a workaround to it?</p>
  
  <p>Here is the code:</p>
  
  <p>Simply create 5 of those threads to work in a background:</p>
  
  <pre><code>private class LongAsync extends AsyncTask&lt;String, Void, String&gt;
  {
      @Override
      protected void onPreExecute()
      {
          Log.d("TestBug","onPreExecute");
          isRunning = true;
      }
  
      @Override
      protected String doInBackground(String... params)
      {
          Log.d("TestBug","doInBackground");
          while (isRunning)
          {
  
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String result)
      {
          Log.d("TestBug","onPostExecute");
      }
  }
  </code></pre>
  
  <p>And then create this thread. It will enter preExecute and hang (it will not go to doInBackground).</p>
  
  <pre><code>private class TestBug extends AsyncTask&lt;String, Void, String&gt;
  {
      @Override
      protected void onPreExecute()
      {
          Log.d("TestBug","onPreExecute");
  
          waiting = new ProgressDialog(TestActivity.this);
          waiting.setMessage("Loading data");
          waiting.setIndeterminate(true);
          waiting.setCancelable(true);
          waiting.show();
      }
  
      @Override
      protected String doInBackground(String... params)
      {
          Log.d("TestBug","doInBackground");
          return null;
      }
  
      @Override
      protected void onPostExecute(String result)
      {
          waiting.cancel();
          Log.d("TestBug","onPostExecute");
      }
  }
  </code></pre>