summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kevin Hufnagle <khufnagle@google.com> 2016-09-26 23:18:43 +0000
committer android-build-merger <android-build-merger@google.com> 2016-09-26 23:18:43 +0000
commit69e48724014be52b97e17fcc11610c1e1c0ae516 (patch)
treee2ecdf2fe6a329cca6d86c59f6decb0ec6020faf
parent746871b077e0ab5f94d700b7b0ca1b58e7ec9dc7 (diff)
parentbd66ef7f2f1832a0e9421297fa141b3df469b02c (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.jd21
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();
+&#64;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 &lt; rawMsgs.length; i++) {
- msgs[i] = (NdefMessage) rawMsgs[i];
+ if (intent != null &amp;&amp; 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>