Android NFC App
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 rea开发者_如何学运维der 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
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.
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.
精彩评论