title: How to Infinite loop an Asynctask?
body: <p>I am working on my school project, so i have a library file that is provided to me which scans a code from the card and returns it. The problem is it only works when i press a button. However, i want it to run always and when i scan a card, it will automaticly return the card id without pressing the button. </p>
  
  <p>It gets the card value partially, card id is totally 16 characters but it takes 3-4 characters at a time. So it is like:</p>
  
  <h2>id=10 id=2310 id=632010 .... id = 123434233632010</h2>
  
  <p>And when there is no card, it returns null.</p>
  
  <p>How can i create a asynctask that runs in background and scans infinitely? And when the code is 16 characters, it stops the task and starts a new activity?</p>
  
  <p>Edit:</p>
  
  <pre><code>    public class TestService extends IntentService {
  
      public int handle, type = 0x26;
      MediaReader md = new MediaReader();
      String cardId;
  
      public TestService() {
          super("TestService");
          // TODO Auto-generated constructor stub
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          while (true) {
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
              try {
                  cardId = "";
                  int ret = md.CardPoll(type);
                  if (ret == 0) {
                      for (int i = 0; i &lt; md.uid_len; i++) {
  
                          cardId = cardId + md.uid[i];
                      }
                      Log.e("MyLogs", cardId);
                  }
              } catch (NullPointerException e) {
                  Log.e("deneme", "No card detected");
              }
  
          }
  
      }
  
  }
  </code></pre>