Reputation: 1495
I am trying to build an application that uses NFC. When user starts certain activity, he will be prompted to approach NFC tag to the reader.
I have red the documentation. I understand I have to create intent filter to receive intents whenever tag is approached.
The problem is I want my activity to receive intent only when it is is visible I don't want it to be started every time the tag is approached. For example app NFC tools works that way.
Upvotes: 0
Views: 649
Reputation: 2804
Register your receiver in your onResume
method, and unregister it in your onPause
method, that way you only receiver the intents while your activity is active.
Upvotes: 0
Reputation: 424
You can do it by using the foreground dispatch system : http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch
Also, remove your intent filter from your manifest, it will stop starting your app
Upvotes: 1