title: Android NFC not opening correct class on tap
body: <p>I have an app with 2 classes, I need my app to open the second class <code>CardActivity</code> when the NFC tag tapped/swiped.  The app opens fine, but <code>MainActivity</code> is run, instead of <code>CardActivity</code>.  </p>
  
  <p>I would hazard a guess that this is an issue with my manifest, but it looks correct.  Here it is regardless:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.spotsofmagic.spotsofmagic"
      android:versionCode="1"
      android:versionName="1.0" android:installLocation="auto"&gt;
  
      &lt;uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" /&gt;
  
      &lt;uses-permission android:name="android.permission.NFC" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
      &lt;uses-feature android:name="android.hardware.nfc" android:required="true" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
  
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
           &lt;activity
              android:name=".CardActivity"
              android:label="@string/app_name" &gt;
  
              &lt;!-- Handle a collectable card NDEF record --&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.nfc.action.NDEF_DISCOVERED"/&gt;
                  &lt;data android:mimeType="application/vnd.spotsofmagic.spotsofmagic"/&gt;
                  &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;/intent-filter&gt;
           &lt;/activity&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I'm confident the tag itself is correct, as I have opened it in another app to view it's contents.  </p>
  
  <p>Below are the two classes.  </p>
  
  <p>CardActivity:</p>
  
  <pre><code>package com.spotsofmagic.spotsofmagic;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnClickListener;
  import android.content.Intent;
  import android.nfc.NdefMessage;
  import android.nfc.NdefRecord;
  import android.nfc.NfcAdapter;
  import android.os.Bundle;
  import android.os.Parcelable;
  import android.util.Log;
  import android.bluetooth.*;
  
  public class CardActivity extends Activity implements OnClickListener {
  
      private static final String TAG = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.card_activity);
  
          // see if app was started from a tag and show game console
          Intent intent = getIntent();
  
          Log.e(TAG, "Hello world.  Intent Type: "+ intent.getType());
  
          if(intent.getType() != null &amp;&amp; intent.getType().equals(MimeType.NFC_DEMO)) {
              Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
              NdefMessage msg = (NdefMessage) rawMsgs[0];
              NdefRecord cardRecord = msg.getRecords()[0];
              String payload = new String(cardRecord.getPayload());
              turnBluetoothOn(payload);
          }
      }
  
      private void turnBluetoothOn(String payload) {
  
          final AlertDialog.Builder builder=new AlertDialog.Builder(this);
          builder.setTitle("Alert Dialog");
          builder.setMessage(payload);
          builder.setIcon(android.R.drawable.ic_dialog_alert);
  
  
          BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
          if (mBluetoothAdapter == null) {
              // Device does not support Bluetooth
          }
          if (!mBluetoothAdapter.isEnabled()) {
              Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
              startActivityForResult(enableBtIntent, 1);
          }
          android.os.Process.killProcess(android.os.Process.myPid());
  
      }
  
      public void onClick(DialogInterface dialog, int which) {
          // TODO Auto-generated method stub
  
      }
  }
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>package com.spotsofmagic.spotsofmagic;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.bluetooth.BluetoothAdapter;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnClickListener;
  import android.content.Intent;
  import android.nfc.NdefMessage;
  import android.nfc.NdefRecord;
  import android.nfc.NfcAdapter;
  import android.os.Bundle;
  import android.os.Parcelable;
  import android.util.Log;
  import android.widget.TextView;
  
  
  public class MainActivity extends Activity implements OnClickListener {
      private static final String TAG = "Activity...";
      private NfcAdapter mAdapter;
      private TextView mTextView;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_activity);
  
          // grab our NFC Adapter
          mAdapter = NfcAdapter.getDefaultAdapter(this);
  
          // TextView that we'll use to output messages to screen
          mTextView = (TextView)findViewById(R.id.text_view);
  
          displayMessage("Loading payload...");
  
      }
  
      private void displayMessage(String message) {
          mTextView.setText(message);
      }
  
      public void onClick(DialogInterface arg0, int arg1) {
          // TODO Auto-generated method stub
  
      }
  }
  </code></pre>
  
  <p>Here is the code I used to write the tag.  This is done on a different app incidentally:</p>
  
  <pre><code>NdefRecord appRecord = NdefRecord.createApplicationRecord("com.spotsofmagic.spotsofmagic");
  
          // record that contains our custom "retro console" game data, using custom MIME_TYPE
          byte[] payload = getPayload().getBytes();
          byte[] mimeBytes = MimeType.NFC_DEMO.getBytes(Charset.forName("US-ASCII"));
          NdefRecord cardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, 
                                                  new byte[0], payload);
          NdefMessage message = new NdefMessage(new NdefRecord[] { cardRecord, appRecord});
  
  // Some code here removed for readability
  
  
   Ndef ndef = Ndef.get(tag);
      if (ndef != null) {
          ndef.connect();
          ndef.writeNdefMessage(message);
  </code></pre>