如果使用 NFC 打开另一个 activity,是否关闭应用程序?
Close the application if another activity is opened with NFC?
我在我的 TagActivity 中使用 TAG_DISCOVERED 操作,如果我的应用程序已经打开,我想在我的 TagActivity 打开之前关闭它。但是,当使用 NFC 打开我的 TagActivity 时,我添加了一些逻辑,以便在按下后退按钮时导航到主 activity,但是已经打开的应用程序仍然存在,当我关闭导航的主应用程序时,它再次显示我以前打开的应用程序。如果我使用 nfc 打开我的 TagActivity,我该如何关闭应用程序?
<activity
android:name=".activities.TagActivity"
android:screenOrientation="portrait" >
<!--Registering app for receiving NFC's TAG_DISCOVERED intent-->
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
编辑: 我以为这个标志解决了我的问题,但显然我没有正确测试它。我的问题的真正解决方案是在 manifest 文件中将 android:launchMode="singleTask"
添加到 my activity。
我在返回时向我的 Intent 添加了 FLAG_ACTIVITY_NEW_TASK 标志,这解决了我的问题。
startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK))
我在我的 TagActivity 中使用 TAG_DISCOVERED 操作,如果我的应用程序已经打开,我想在我的 TagActivity 打开之前关闭它。但是,当使用 NFC 打开我的 TagActivity 时,我添加了一些逻辑,以便在按下后退按钮时导航到主 activity,但是已经打开的应用程序仍然存在,当我关闭导航的主应用程序时,它再次显示我以前打开的应用程序。如果我使用 nfc 打开我的 TagActivity,我该如何关闭应用程序?
<activity
android:name=".activities.TagActivity"
android:screenOrientation="portrait" >
<!--Registering app for receiving NFC's TAG_DISCOVERED intent-->
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
编辑: 我以为这个标志解决了我的问题,但显然我没有正确测试它。我的问题的真正解决方案是在 manifest 文件中将 android:launchMode="singleTask"
添加到 my activity。
我在返回时向我的 Intent 添加了 FLAG_ACTIVITY_NEW_TASK 标志,这解决了我的问题。
startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK))