android - 在特定任务中使用 NFC 启动 Activity

标签 android android-intent nfc

我的应用程序包含许多 Activity 。这些 Activity 之一响应 NFC Intent 过滤器以及标准 Intent ,但是,该 Activity 是在它自己的任务中启动的,而不是在与应用程序相同的任务中启动的。当 NFC Intent 启动时,应用程序不一定正在运行,但如果是,我希望该 Activity 在同一任务中启动,以确保无缝的用户体验。目前,该应用程序的行为就好像有 2 个正在运行。

这是我的 NFC Activity 的 list :

<activity
        android:name="name.subname.app.activity.ItemSummaryActivity"
        android:label="@string/title_activity_item_summary" >
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />

            <data android:mimeType="application/vnd.name.nfcdemo" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

是否可以启动现有任务中的 Activity(如果存在)?

最佳答案

我在这里看到两个选项:

1) 将 android:launchMode="singleTask" 添加到 list 中的 Activity 标签中:

<activity
        android:name="name.subname.app.activity.ItemSummaryActivity"
        android:label="@string/title_activity_item_summary"
        android:launchMode="singleTask" >

"singleTask" :

The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

2) 供应 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT标记为 startActivity() Intent 。但是,如果 Activity 是由 NFC 触发的(并且使用此选项不可行)请考虑什么 @NFC guy不得不说here .

关于android - 在特定任务中使用 NFC 启动 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20451687/

相关文章:

android - 打开卡上的文件夹

java - 如何在Intent中发送模型的对象

Android 插件 (ADT) v10.0 在可视布局编辑器中丢失了 "clipping"切换?

java - 链式动画不适用于 AnimatorSet

java - 在 Activity 中保存数据

android - NFC/SWP接入SIM卡的UID

c# - 如何在 xamarin.forms 中使用 CoreNFC?

linux - debian 中未安装 libudev-dev

安卓短信通知问题

java - 如何通过在android中随机方向拖动4个点来在android中创建不规则四边形