chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 559 forks source link

Intents cause issuse if app is already open #127

Closed JohnMcLear closed 10 years ago

JohnMcLear commented 10 years ago

This was due to the app already being open.. If I force close the app then open it with an intent it works..

Basically you use cordova run android then press the home button then launch a browser, hit share, select the app and it will fail because the app is already "running"..

don commented 10 years ago

This sounds familiar. We fixed similar issues in the past by adding android:noHistory="true" to the activity. Info is from this comment but TBH, I can't recall the exact details.

JohnMcLear commented 10 years ago

I'm not convinced noHistory is right for me as noHistory covers more the history of navigating through an app. My issue is that the listeners try to re-attached when they are already attached as far as I can tell..

http://stackoverflow.com/questions/11836080/how-does-androidnohistory-true-work for reading on noHistory.

don commented 10 years ago

Can you check to see if the listen exists before re-adding? If you have sample code to break I can look at later this week.

JohnMcLear commented 10 years ago

Is there a method for seeing if it's listening? I did look for one but failed..

JohnMcLear commented 10 years ago

Trying android:launchMode="singleTask" to the activity in the manifest

JohnMcLear commented 10 years ago

Hrm, By jove this seems to have cracked it :)

JohnMcLear commented 10 years ago

Actually maybe not, what this fix does it just redirect you back to the original app, blah. I wonder if there is a way to fire an event when an intent arrives instead of checking for it on startup?

don commented 10 years ago

Only one app is good thing.

Do you have a mime-type handler to catch the intent fired by scanning the tag? Due to some legacy stuff, a ndef-mine event is fired. See http://stackoverflow.com/questions/23059763/chariotsolutions-phonegap-nfc-plugin-intent

JohnMcLear commented 10 years ago

Trying something else, trying to exit my app on pause..

JohnMcLear commented 10 years ago

You will wanna add android:launchMode="singleTask" to your activity to stop this from happening then ensure whatever intent plugin you use supports handling new intents while an app is open (but in the background..)..

It might make sense to make the plugin add android:launchMode="singleTask" anyway because you don't want two instances of listeners, I don't think?