[英]onNewIntent() being called in onResume() multiple times
My problem is that in onNewIntent() function I start a new intent to open contacts app and allow the user the complete the process of creating a new contact, but when I try to exit the contacts app and go back to my app it seems that onNewIntent() is called again most likely due to this block of code.我的问题是在 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());
}
}
Is there a way to clear intents once onNewIntent (called by processIntent) has been called.一旦 onNewIntent(由 processIntent 调用)被调用,有没有办法清除意图。
It looks like you could just call setIntent()
at the end of onNewIntent()
with a new Intent that has an Action value that will not trigger further processing.它看起来像你可以只调用setIntent()
在结束onNewIntent()
用新的原意,即具有不会引发进一步的处理措施值。
Here is an example, where the new Intent for the Activity is set with an Action of "do_nothing":这是一个示例,其中 Activity 的新 Intent 设置为“do_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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.