How to keep an Android PendingIntent from always creating a new Activity

Solution: Put android:launchMode="singleTask" for your activity (or activities) in the manifest (AndroidManifest.xml). That does the trick. Whenever an NFC intent is dispatched by the system, always a new Activity will be created. This is unique for NFC intents. So setting android:launchMode="singleTop" will not work, nor will setting flags in the PendingIntent.

As an important addition to those notes, setting the android:launchMode="singleTask" has the effect of enabling the onNewIntent method in the target Activity, so you can capture the Intent/PendingIntent like this:

protected void onNewIntent(Intent intent) {
    String landingPageQuoteOption = intent.getStringExtra(GlobalState.LANDING_PAGE_INTENT_KEY);
    if (landingPageQuoteOption != null) {
         Log.i(TAG, "(onNewIntent), quote was not null (GOOD)");
         showLandingPage(landingPageQuoteOption);
    } else {
        Log.i(TAG, "(onNewIntent), quote WAS null (BAD)");
    }
}

Note that the Intent can also cause the Activity to be started, so you’ll want to catch it in your Activity’s onCreate method as well. Based on my recent experience, the intent will hit one of those two methods, depending on the state of your Android application when the PendingIntent is fired.