Android意图过滤器问题

Android意图过滤器问题,android,android-intent,intentfilter,Android,Android Intent,Intentfilter,我创建了一个意图过滤器,用于在单击指定链接(如“”)时打开我的应用程序。当我点击链接时,我被要求打开应用程序,好的,一切正常。然后,我通过反复单击后退按钮退出应用程序,直到所有活动都关闭。但是: 从启动器再次启动应用程序后,它会收到与应用程序相同的意图数据 在我点击链接之前。如何避免它 当我从一个链接打开我的应用程序时,如我在应用程序管理器中看到的,WhatsApp就是打开的应用程序!为什么? 这是我当前的清单代码: <activity android:name="

我创建了一个意图过滤器,用于在单击指定链接(如“”)时打开我的应用程序。当我点击链接时,我被要求打开应用程序,好的,一切正常。然后,我通过反复单击后退按钮退出应用程序,直到所有活动都关闭。但是:

  • 从启动器再次启动应用程序后,它会收到与应用程序相同的意图数据 在我点击链接之前。如何避免它

  • 当我从一个链接打开我的应用程序时,如我在应用程序管理器中看到的,WhatsApp就是打开的应用程序!为什么?

  • 这是我当前的清单代码:

        <activity
            android:name="com.x.y.SplashActivity"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
    
                <data
                    android:host="@string/app_host"
                    android:pathPrefix="/events/"
                    android:scheme="http" />
            </intent-filter>
        </activity>
    

    关于2。您的活动成为WhatsApp任务的一部分。链接页面提到了一些你可以控制的事情(主要是在清单中)你的活动应该如何与任务交互,应该如何启动等等。例如,听起来很有趣,但我不知道这是否是你需要的。为什么你有
    android:noHistory=“true”
    ?请在你的
    onCreate()中发布一些代码
    我刚刚亲自测试过,它工作正常。第一次使用包含ACTION=VIEW的
    意图调用它时。第二次(当我从主屏幕启动应用程序时),它会得到一个包含ACTION=MAIN的
    Intent
    。你在做别的奇怪的事。我无法重现这个问题。您可以尝试将启动活动与浏览活动分开。创建一个新的活动,其中包含URL的
    。在该活动的
    onCreate()
    中,只需启动
    splash活动
    ,并将URL作为额外内容传递。看看这是否有帮助。
        // Retrieve the Intent
        Intent intentUri = getIntent();
    
        // Check URI
        Uri uri = intentUri.getData();
    
        if (uri != null) {
            // Try to extract the data
            // For now, data could be a public event id, so parse it
            List<String> pathSegments = uri.getPathSegments();
    
            // Check validity
            if (pathSegments.size() > 2) {
                // Finally, get the public event id
                String publicEventId = pathSegments.get(2);
    
                // Set poll as responded
                user.setPollEventId(publicEventId);
            }
    
            // Remove the intent to prevent further calls
            setIntent(null);
        }
    
        // Open the main activity normally
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);