[英]Android NFC and onNewIntent()
在NFC活動中編寫onNewIntent(Intent intent)
方法時,調用super.onNewIntent(intent)
是否必要/正確?
我問是因為這個官方示例包括它:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
...
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.
...
}
}
}
但這另一個官方示例卻沒有:
public void onNewIntent(Intent intent) {
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
//do something with tagFromIntent
}
大概,第二個示例是不完整的(並且不正確),但是我想確定一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.