Reputation: 1266
I'm writing not so complicated application but I have a big problem;)
In my application are some activities first, login page than, nfc tag reader and than, some menu. My question is how to catch in my second activity that intent with discoverd tag with out restarting activity? What to use
Upvotes: 0
Views: 1093
Reputation: 2636
You need to use enableForegroundDispatch(activity, pendingIntent, null, null) and then make sure the pendingIntent wraps an intent that has the flag SINGLE_TOP. The intent should start the same activity, and because SINGLE_TOP is used the activity currently in memory will just be used. onNewIntent() is called and you can then extract the tag out of the intent.
Upvotes: 0
Reputation: 5173
Take a good look at the foreground dispatch system capability as described on the NfcAdapter page (enableForegroundDispatch()). Your activity can call a method to basically intercept a tag intent that you're interested in; your activity gets priority over all other activities. You'll get the tag delivered to you in the onNewIntent() callback of your existing activity.
Upvotes: 1