You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AndroidManifest配置多Activity及闪屏传递原始Intent到MainActivity咨询

调整Manifest配置

修改规则如下:

  1. 删除MainActivity的MAIN/LAUNCHER Intent过滤器,避免桌面出现两个应用图标
  2. 将原本配置在MainActivity下的NDEF_DISCOVERED Intent过滤器移动到SplashScreenActivity下,保证NFC触发时优先启动闪屏页
<activity
    android:name=".SplashScreenActivity"
    android:theme="@style/Theme.MyApp.SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <!-- 原MainActivity的NDEF过滤器移到这里 -->
    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="http"
              android:host="<my custom domain>"/>
    </intent-filter>
</activity>

<activity android:name=".MainActivity" android:theme="@style/Theme.MyApp.NoActionBar">
    <!-- 删除这里的MAIN/LAUNCHER过滤器,只保留业务逻辑即可 -->
</activity>

修改SplashScreenActivity跳转逻辑

原代码新建了空Intent导致数据丢失,直接复用系统传递给闪屏页的原始Intent即可,所有NDEF相关的Extra数据会完整传递到MainActivity:

public class SplashScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 复用原始Intent,只修改跳转目标类
        Intent intent = getIntent();
        intent.setClass(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

MainActivity适配说明

你现有的readFromIntent方法无需修改,只需要在onCreate生命周期中调用该方法传入getIntent()即可正常获取NDEF数据。如果应用有后台运行时触发NFC的场景,额外在onNewIntent回调中也调用一次readFromIntent即可。

内容的提问来源于stack exchange,提问作者Courtney Sampson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 03:24:03