onNewIntent() being called in onResume() multiple times

2.4k views Asked by At

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.

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

1

There are 1 answers

0
Daniel Nugent On BEST ANSWER

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.

Here is an example, where the new Intent for the Activity is set with an Action of "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);
    }
}