Tuesday, 15 July 2014

android - Dont start new activity on new intent, take the old activity -



android - Dont start new activity on new intent, take the old activity -

im using nfc , im working intents. when nfc tag discovered start nfcactivity.

<activity android:name="controller.nfcactivity" android:launchmode="singletask" > <intent-filter> <action android:name="android.nfc.action.tech_discovered" /> <category android:name="android.intent.category.default" /> </intent-filter> <meta-data android:name="android.nfc.action.tech_discovered" android:resource="@xml/nfc_tech_filter" /> </activity>

the nfcactivity activity without ui. starts nfcreadertask.

string action = intent.getaction(); if (nfcadapter.action_tech_discovered.equals(action)) { tag tagfromintent = intent.getparcelableextra(nfcadapter.extra_tag); nfcdatadevice datadevice = new nfcdatadevice(); datadevice.setcurrenttag(tagfromintent); byte[] systeminfoanswer = nfccommand.sendgetsysteminfocommandcustom(tagfromintent, new nfcdatadevice()); if (ndefhelper.decodesysteminforesponse(systeminfoanswer, new nfcdatadevice())) { nfcreadertask nfcreadertask = new nfcreadertask(this, this, datadevice); nfcreadertask.execute(); } }

when readertask finished callback method onnfcreadertaskcompleted in nfcactivity called , that:

public void onnfcreadertaskcompleted(long time, string value) { intent newintent = new intent(this.getapplicationcontext(), nfcresultactivity.class); newintent.setflags(intent.flag_activity_clear_top); newintent.putextra(globals.key_nfc, true); newintent.putextra(globals.key_time, time); newintent.putextra(globals.key_value, value); this.startactivity(newintent); this.finish(); }

that fine first time nfc tag discovered. want dont start new nfcresultactivity always. when nfcresultactivity active want phone call method of nfcresultactivity set new info , not create new activity.

how can accomplish that?

just edit line.

newintent.setflags(intent.flag_activity_clear_top|intent.flag_activity_single_top);

or

<activity android:name="controller.nfcactivity" android:launchmode="singletop" >

android android-intent

No comments:

Post a Comment