title: Running many Asynctask on timer(countdowntimer)
body: <p>I have created a <code>CountDownTimer</code> like this</p>
  
  <pre><code>public class MyCountDownTimer extends CountDownTimer {
          public MyCountDownTimer(long startTime, long interval) {
          super(startTime, interval);
          }
  
          @Override
          public void onFinish() {
          //timeout
          }
  
          @Override
          public void onTick(long millisUntilFinished) { 
           PaymentAsyncTask paymentTask = new PaymentAsyncTask(this);
           paymentTask.execute();
  
          }
  }
  </code></pre>
  
  <p>in <code>onPostExecute</code> of <code>paymentTask</code>, i am doing some operations on some specific condition.</p>
  
  <p>Basically, i am checking from some website, after some time interval(say 3 second), task has been completed or not.</p>
  
  <p><strong>Now if internet runs fast, there is no issue with this code,</strong></p>
  
  <p><strong>if task gets completed,i cancel the timer in onPostExecute and do my further work.</strong></p>
  
  <p>But if internet runs <strong>slow</strong>, which means response doesn't come in 3 seconds,
  <code>onPostExecute</code> is called more than once(<strong>executing code inside it more than once</strong>), while the task was already completed, its just that i got the response late due to server issue/internet delay.</p>
  
  <p>How i can make sure that code inside <code>onPostExecute</code> gets called only once?</p>
  
  <p>Possible approaches:</p>
  
  <ol>
  <li>Take some static flag variable, make it true and check in others...</li>
  </ol>
  
  <p>I am looking for some solution, which is reliable, maybe android provides some mechanism to <strong>synchronise</strong> this.. Thanks</p>