簡體   English   中英

Android NFC和onNewIntent()

[英]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
}

大概,第二個示例是不完整的(並且不正確),但是我想確定一下。

根據官方文檔 ,沒有理由調用super.onNewIntent(..)

例如,您可以查看onDestroy()方法文檔 它包括下一行:

派生類必須調用此方法的超類的實現。 如果不這樣做,將引發異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM