After my old question was closed I'm trying it now again considering the advices you gave me...
I've got an Android-Test-App in which I want to change the text a TextView as soon as something (f.e. RFID chip) is read with NFC.
The problem is that my activity with the TextView lies in the Tab of a TabHost. When NFC is reading something the Activity is started in the foreground and the TextView is not changed. What I want is that only the TextView changes and everything else stays as it is....
Here's my code:
My TabActivity:
public class NfcTabsActivity extends TabActivity {
private NfcAdapter nfc;
private PendingIntent nfcintent;
private String[][] nfctechfilter = new String[][] { new String[] { NfcA.class.getName() } };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
Intent intent = new Intent().setClass(this, NfcTest.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TabSpec spec = tabHost.newTabSpec("nfctab").setIndicator("NFC").setContent(intent);
tabHost.addTab(spec);
nfc = NfcAdapter.getDefaultAdapter(this);
// PendingIntent using the NfcTest-Activity to receive the Intent. (Am I doing this correctly??)
nfcintent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
}
// Start looking for NFC when activity is started/resumed.
@Override
protected void onResume() {
super.onResume();
nfc.enableForegroundDispatch(this, nfcintent, null, nfctechfilter);
}
// Disable NFC when leaving activity
@Override
protected void onPause() {
super.onPause();
nfc.disableForegroundDispatch(this);
}
}
and here's my NfcTest Activity that should receive the intent when NFC is used:
public class NfcTest extends Activity {
private TextView status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nfctest);
status = (TextView) findViewById(R.id.textView2);
}
@Override
public void onNewIntent(Intent intent) {
status.setText("RFID detected...");
}
}
Thanks NFC guy for the advice to put the PendingIntent in the TabActivity! Unfortunately - as I said in the other thread - that doesn't work neither for me... :( Maybe I did something wrong in my code?
Here's the activity definition in my AndroidManifest.xml:
[...]
<activity android:name=".NfcTest" android:clearTaskOnLaunch="true" android:alwaysRetainTaskState="true" android:finishOnTaskLaunch="true"></activity>
[...]
Can anyone help me with this problem? Maybe you NFC guy? Maybe I only understand something wrong on your idea or mixed something up in my code...? :/