onNewIntent()多次在onResume()中调用

时间:2015-06-15 01:04:42

标签: android nfc nfc-p2p

我的问题是在onNewIntent()函数中我启动了一个打开联系人应用程序的新意图,并允许用户完成创建新联系人的过程,但是当我尝试退出联系人应用程序并返回到我的应用程序时似乎再次调用onNewIntent()很可能是由于这段代码。

@Override
public void onResume() {
    super.onResume();
    // Check to see that the Activity started due to an Android Beam
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        processIntent(getIntent());
    }
}

一旦调用onNewIntent(由processIntent调用),是否有办法清除意图。

1 个答案:

答案 0 :(得分:3)

看起来您可以在setIntent()的末尾使用具有不会触发进一步处理的Action值的新Intent调用onNewIntent()

这是一个例子,其中Activity的新Intent设置为Action“of_nothing”:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    //Do your current processing here:
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        //process intent
        //.........

        // set intent for Activity to new Intent with "do_nothing" as action
        Intent i = new Intent();
        i.setAction("do_nothing");
        setIntent(i);
    }
}
相关问题