diff options
| author | 2016-09-26 23:18:43 +0000 | |
|---|---|---|
| committer | 2016-09-26 23:18:43 +0000 | |
| commit | 69e48724014be52b97e17fcc11610c1e1c0ae516 (patch) | |
| tree | e2ecdf2fe6a329cca6d86c59f6decb0ec6020faf | |
| parent | 746871b077e0ab5f94d700b7b0ca1b58e7ec9dc7 (diff) | |
| parent | bd66ef7f2f1832a0e9421297fa141b3df469b02c (diff) | |
docs: Revised "activity launched with NFC intent" code sample to demonstrate using onNewIntent() in these situations
am: bd66ef7f2f
Change-Id: Ie529ad5adcddeef400d9eb3dec5f31cafa677dbe
| -rw-r--r-- | docs/html/guide/topics/connectivity/nfc/nfc.jd | 21 |
1 files 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 520f52017097..881a75f2512d 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.</p> <pre> -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 } </pre> |