title: Execute AsyncTask loop after previous one
body: <p>I want to check unread messages after 30 seconds of previous check, means when the first check (<code>AsyncTask</code>) is complete and I have the result then I want to wait 30 seconds, then I want to check for unread messages again and so on. Here is my code:</p>
  
  <pre><code>    TimerTask timerTask = new CheckUnreadMessages(menuItem);
      Timer timer = new Timer();
      timer.schedule(timerTask, Constants.CHECK_UNREAD_COUNT_INTERVAL);
  </code></pre>
  
  <p>Here is my <code>TimerTask</code>:</p>
  
  <pre><code>class CheckUnreadMessages extends TimerTask{
      MenuItem menuItem;
  
      public CheckUnreadMessages(MenuItem menuItem) {
          this.menuItem = menuItem;
      }
  
      @Override
      public void run() {
          Log.i("PrivateHome", "Checking for unread message...");
          new CheckUnreadMessagesTask(menuItem, PrivateHome.this).execute(LocalDBSP.init().getID(PrivateHome.this));
      }
  }
  </code></pre>
  
  <p>Here goes my <code>AsyncTask</code>:</p>
  
  <pre><code>public class CheckUnreadMessagesTask extends AsyncTask &lt;String, String, Boolean&gt; {
      Activity activity;
      JSONObject result;
      MenuItem menuItem;
  
      public CheckUnreadMessagesTask(MenuItem menuItem, Activity activity){
          this.menuItem = menuItem;
          this.activity = activity;
      }
  
      @Override
      protected Boolean doInBackground(String... params) {
          try {
              //now update to server
              result = getResponse(URLManager.getUnreadCount(params[0]));
              return JSONHelper.isResultOK(result);
          }catch (Exception e){
              e.printStackTrace();
          }
          return false;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected void onPostExecute(Boolean resultOK) {
          super.onPostExecute(resultOK);
  
          if(resultOK){
              try {
                  String count = result.getString(JSONKeys.RESULT);
                  menuItem.setTitle(Constants.NAV_SEE_MESSAGES_TITLE+" ("+count+")");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>But it's being executed for the first time only, it's not repeating.</p>