简体   繁体   English

Android NFC和onNewIntent()

[英]Android NFC and onNewIntent()

When writing the onNewIntent(Intent intent) method in an NFC Activity, is it neccessary/correct to call super.onNewIntent(intent) ? 在NFC活动中编写onNewIntent(Intent intent)方法时,调用super.onNewIntent(intent)是否必要/正确?

I ask because this official example includes it: 我问是因为这个官方示例包括它:

@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.
            ...
        }
    }
}

But this other official example doesn't: 但这另一个官方示例却没有:

public void onNewIntent(Intent intent) {
    Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    //do something with tagFromIntent
}

Presumably, the second example is incomplete (and incorrect) but I would just like to be sure. 大概,第二个示例是不完整的(并且不正确),但是我想确定一下。

Based on official documentation there's no reason to call super.onNewIntent(..) . 根据官方文档 ,没有理由调用super.onNewIntent(..)

As an example you could check onDestroy() method documentation . 例如,您可以查看onDestroy()方法文档 It includes next line: 它包括下一行:

Derived classes must call through to the super class's implementation of this method. 派生类必须调用此方法的超类的实现。 If they do not, an exception will be thrown. 如果不这样做,将引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM