From bd66ef7f2f1832a0e9421297fa141b3df469b02c Mon Sep 17 00:00:00 2001 From: Kevin Hufnagle Date: Mon, 19 Sep 2016 12:45:31 -0700 Subject: [PATCH] docs: Revised "activity launched with NFC intent" code sample to demonstrate using onNewIntent() in these situations Bug: 17129447 Change-Id: I6e60b273f8138be918708f59402866ae617af0cb --- .../html/guide/topics/connectivity/nfc/nfc.jd | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/html/guide/topics/connectivity/nfc/nfc.jd b/docs/html/guide/topics/connectivity/nfc/nfc.jd index 520f520170976..881a75f2512db 100644 --- a/docs/html/guide/topics/connectivity/nfc/nfc.jd +++ b/docs/html/guide/topics/connectivity/nfc/nfc.jd @@ -487,19 +487,22 @@ intent. The following example checks for the {@link android.nfc.NfcAdapter#ACTIO intent and gets the NDEF messages from an intent extra.

-public void onResume() {
-    super.onResume();
+@Override
+protected void onNewIntent(Intent intent) {
+    super.onNewIntent(intent);
     ...
-    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
-        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
-        if (rawMsgs != null) {
-            msgs = new NdefMessage[rawMsgs.length];
-            for (int i = 0; i < rawMsgs.length; i++) {
-                msgs[i] = (NdefMessage) rawMsgs[i];
+    if (intent != null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
+        Parcelable[] rawMessages =
+            intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+        if (rawMessages != null) {
+            NdefMessage[] messages = new NdefMessage[rawMessages.length];
+            for (int i = 0; i < rawMessages.length; i++) {
+                messages[i] = (NdefMessage) rawMessages[i];
             }
+            // Process the messages array.
+            ...
         }
     }
-    //process the msgs array
 }