My Android application is using an intent-filter on the event “NDEF_DISCOVERED” to get opened if it contains a certain URL. It works fine but I have noticed that, if I put my application in background and tap a NFC Tag, a new instance of the program is started. If I do that a few times, I get several instances of my application created. This is causing me some problems so I would like to find a solution so that only one instance gets opened.
A side comment: When my program is in foreground, I’m using enableForegroundDispatch() in onResume and disableForegroundDispatch() in onPause. It works fine.
When my program is in background and when I tap an NFC Tag, is there a way that the system detects that the program is already started and put it in foreground instead of starting a new instance?
As a matter of comparison, if I put my program in background, go to the list of programs and click on my program, Android detects that this program is already opened and resume it without creating a new instance (onCreate() of MainActivity is not called in that case). Why don’t we have the same behavior with NFC events and is it possible to have the same behavior?
I have read this thread (Application receiving NFC always pops up new instance in front ) which is the same question but it didn’t help me to find a solution.