Android NFC activity being relaunched even though its on the top of the stack -


i'm guessing of face palmed when saw title, , thought we've seen before agree, i've tried solve issue , wont remedy. here goes.

my app can launched home screen(icon) , works ok scans nfc tag , sends relevant data server. want app launched nfc tag, no problem. however! when app launched via nfc tag remove phone , re-present tag should read tag , send data server. same behaviour launching app via the icon, when scan nfc tag time new instance of app launched kicks current instance down stack, version of instance busy reading tag anr.

in nutshell:
home screen -> scan tag -> app launches.
rescan tag->
current instance of app disappears replaced new instance. want previous instance stay , work.

a few guesses me @ point that: -the nfc not getting registered app, hence the os doing default behaviour.
-there flag not being set correctly when launched via nfc tag telling os activity not need relaunched.

anyway here's code:

<uses-permission android:name="android.permission.nfc"/>  <intent-filter>             <action android:name="android.nfc.action.ndef_discovered" />             <category android:name="android.intent.category.default" />             <data android:scheme="http"android:host="@string/url_for_intent_filtering" android:pathprefix="/id/" /> 

//procedure of nfc startup called oncreate private void startnfc() {     mnfcadapter = nfcadapter.getdefaultadapter(this);     if(! mnfcadapter.isenabled())//check nfc switched on     {         mmainactivityhandler.sendemptymessage(nfc_disabled);     }      //its ok carry on , instantiate nfc though not enabled.     if(mnfcadapter != null)     {         int requestid = (int) system.currenttimemillis();         mpendingintent = pendingintent.getactivity(this, requestid, new intent(this, getclass()).addflags(intent.flag_activity_single_top), pendingintent.flag_update_current);          intentfilter intentf = new intentfilter(nfcadapter.action_ndef_discovered);         intentf.adddatascheme("http");          intentfilter = new intentfilter[] {intentf};            if(debug) log.i("debug","+++++++++++++++++++++++++++++++++++++++++++++++ nfc has been started");      }else     {         //we have problem nfc adapter because device doesn't have one.         if(debug) log.i("debug","+++++++++++++++++++++++++++++++++++++++++++++++ nfc has failed");         mmainactivityhandler.sendemptymessage(nfc_failed);     } } 

@override protected void onpause() {     if(debug) log.i("ma","+++++++++++++++++++++++++++++++++++++++ on pause");     try{         mnfcadapter.disableforegrounddispatch(this);     }catch(exception e)     {      }     super.onpause(); } 

//and here should reinstate nfc adapter @override protected void onresume() {     if(debug) log.i("ma","+++++++++++++++++++++++++++++++++++++++ on resume");      //setupdatalistener(true);     setupservercomms(getapplicationcontext());     //mnfcadapter.enableforegrounddispatch(this,mpendingintent,intentfilter,null);     mnfcadapter.enableforegrounddispatch(this,mpendingintent,null,null);     super.onresume(); } 

just add line in androidmanifest.xml activity , done.

        android:launchmode="singletask" 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -