title: How to stop my Android NFC app looping when it is close to NFC (smartcard)
body: <p>My Android nfc app, when it has finished reading a smart card, is presented again with the same NFC tag info and gets launched again by the operating system. In fact if you don't move the phone it goes into a permanent loop.
  The amount of data being read does take one or two seconds so at the end it starts again.
  (This is fairly common on my Galaxy S2 Gingerbread and my S3 on ICS)</p>
  
  <p><strong>How do I stop it repeating when the NFC source (smart card) didn't change and was not moved away from the phone?</strong></p>
  
  <p>My activity has an intent filter of:</p>
  
  <pre><code>            &lt;intent-filter &gt;
                  &lt;action android:name="android.nfc.action.TECH_DISCOVERED" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                  &lt;action android:name="android.nfc.action.TAG_DISCOVERED" /&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data
                  android:name="android.nfc.action.TECH_DISCOVERED"
                  android:resource="@xml/filter_nfc" /&gt;
  </code></pre>
  
  <p>With a tech list of</p>
  
  <pre><code> &lt;tech-list&gt;
       &lt;tech&gt;android.nfc.tech.IsoDep&lt;/tech&gt;
   &lt;/tech-list&gt;
  </code></pre>
  
  <p>The source code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      resolveIntent(getIntent());
  }
  
  @Override
  public void onNewIntent(Intent intent) {
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);
  }
  
  private void resolveIntent(Intent intent) {
              intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      final String action = intent.getAction();
      if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
                   || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
          ....work
          handled = true;
      }
      if (!handled) {
          Log.e(tag, "Unknown intent " + intent);
          finish();
          return;
      }
  }
  </code></pre>