Android:如何在应用程序的其他活动中临时处理Intent? [英] Android: How do I temporarily handle an Intent in a different activity of my application?

查看:83
本文介绍了Android:如何在应用程序的其他活动中临时处理Intent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发支持NFC的应用程序.今天,我的清单中有一个意图过滤器,用于处理具有NDEF记录的NFC凸起":

I am developing an application that is NFC-aware. Today I have an intent-filter in my manifest for handling NFC "bumps" that have NDEF records:

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="wifi" />
  <data android:scheme="socket" />
</intent-filter>

这很好用.

该应用程序具有选择项目"活动和查看"活动.如当前所写,该意图是在我的选择一项"活动的上下文中处理的.但是,当应用程序处于查看"活动时,我希望查看"处理所有NFC意图,而不是选择项目"活动.当查看"活动不再位于堆栈中时,我希望通过选择一项"活动再次处理NFC的颠簸".

The app has a "select an item" activity and a "view" activity. As currently written, the Intent is handled in the context of my "select an item" activity. When the app is in the "view" activity, however, I would like the "view" to handle any NFC Intents instead of the "select an item" activity. When the "view" activity is no longer on the stack, I'd like any NFC "bumps" to again be handled by the "select an item" activity.

发生这种情况的正确/最佳方法是什么?还要注意,在这种情况下,我不希望弹出哪个应用程序/活动"选择器,因为这会使体验特别繁琐和令人困惑.

What is the right/best way to have this happen? Note too that I would not like to see the "which app/activity" selector pop up in this case, since that would make the experience particularly tedious and confusing.

推荐答案

当您的活动(视图"或选择项目")位于前台时,您可以使用前台分派来检测新标签.请参阅NfcAdapter的

While your activity (either "view" or "select an item") is in the foreground, you can use the foreground dispatch to detect new tags. See the NfcAdapter's enableForegroundDispatch() method. An activity that is registered with the foreground dispatch will take precedence over intent filter's in the app manifests.

这篇关于Android:如何在应用程序的其他活动中临时处理Intent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆