3

私の古い質問が閉じられた後、あなたがくれたアドバイスを考慮して、もう一度試しています...

NFC で何か (RFID チップ) が読み取られるとすぐにテキストを TextView に変更したい Android-Test-App があります。

問題は、TextView での私のアクティビティが TabHost のタブにあることです。NFC が何かを読み取っている場合、Activity はフォアグラウンドで開始され、TextView は変更されません。私が望むのは、TextView のみが変更され、他のすべてはそのままであるということです....

これが私のコードです:

私のタブアクティビティ:

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);
    }
}

NFC が使用されている場合にインテントを受け取るNfcTest アクティビティを次に示します。

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...");

    }
}

PendingIntent を TabActivity に入れるようにアドバイスしてくれたNFC担当者に感謝します。残念ながら、他のスレッドで言ったように、それは私にとってもうまくいきません... :( コードで何か間違ったことをしたのでしょうか?

AndroidManifest.xmlのアクティビティ定義は次のとおりです。

        [...]
        <activity android:name=".NfcTest" android:clearTaskOnLaunch="true" android:alwaysRetainTaskState="true" android:finishOnTaskLaunch="true"></activity>
        [...]

誰でもこの問題を解決できますか? 多分あなたはNFCの男ですか?たぶん、私はあなたの考えに何か問題があるか、私のコードに何かが混じっているだけだと思います...? :/

4

1 に答える 1

0

これを試して

        Intent intent = new Intent().setClass(this, NfcTest.class);

    TabSpec spec = tabHost.newTabSpec("nfctab").setIndicator("NFC").setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    tabHost.addTab(spec);
于 2013-07-02T20:32:55.213 に答える