Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Existing Activity Instance Must handle implicit NFC intent

I'm writing a kiosk-like micro-browser which opens specific pages based on payload of specific scanned RFID tags.

In order to both provide a method for reopening the app (the app is for public use) and handling all RFID scans, I'm trying to make my app handle all android.nfc.action.NDEF_DISCOVERED actions with a single instance of the main activity.

Currently, every time a new RFID tg is scanned, a new instance of my activity opens, whether or not there was one already open. Obviously, this is not ideal. Can a single instance of an activity handle all of these implicit intents?

I've already looked at using the singleTop attribute and flag, but I don't know of a way to set a flag for an implicit intent caused by an external system-generated intent, ie discovering an NFC tag.

this is my first time asking my own question here, so I'm sorry if that didn't make much sense.

like image 890
medavox Avatar asked May 06 '26 01:05

medavox


1 Answers

This link answered the question for me, as explained in the comment i made (before I could answer this myself).

http://www.java2s.com/Code/Android/Core-Class/AnexampleofhowtousetheNFCforegrounddispatchAPIs.htm

My problem was I didn't know of/use a PendingIntent, which seems to be some kind of archetype you can use to specify properties (namely the eponymous flags) to later types of Intents.

like image 84
medavox Avatar answered May 08 '26 16:05

medavox