简体   繁体   English

Android - NFC标签检测用户何时进行其他活动

[英]Android - NFC tag detect when user in some other activity

I used the NFC tag for application launching.but when other activities are running and i touch the tag to device the NFC application is launching again. 我使用NFC标签进行应用程序启动。但是当其他活动正在运行时,我触摸标签到设备,NFC应用程序再次启动。

manifest: 表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.testnfc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="14" />

    <uses-permission android:name="android.permission.NFC" />

    <uses-feature
        android:name="android.hardware.nfc"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.test.testnfc.TestNFCActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.test.testnfc.NFCLoginActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />



            </intent-filter>

        </activity>
        <activity android:name="com.test.testnfc.FirstActivity" >
        </activity>
        <activity android:name="com.test.testnfc.SecondActivity" >
        </activity>
        <activity android:name="com.test.testnfc.ThirdActivity" >
        </activity>
        <activity android:name="com.test.testnfc.FourthActivity" >
        </activity>
        <activity android:name="com.test.testnfc.FifthActivity" >
        </activity>
    </application>

</manifest>

I don't want this.Instead it should stay in the same activity. 我不想要这个。相反它应该保持相同的活动。 Any idea about this? 对此有何想法?

Move the intent-filter for NFC detection into a Service, so that when a tag is discovered a Service is started instead of an Activity. 将用于NFC检测的intent-filter移动到Service中,以便在发现标记时启动Service而不是Activity。

You can then use the Service to decide what you want to do and which Activity to launch. 然后,您可以使用该服务来决定要执行的操作以及要启动的活动。

Try set this properties in manifest for that activity: 尝试在该活动的清单中设置此属性:

android:clearTaskOnLaunch="true"
android:launchMode="singleTop"

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM