Android Deeplink 打开应用程序两次

K1-*_*ria 4 java android deep-linking webview android-studio

我使用 webview 创建应用程序并实现深度链接,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ariagp.myapplication">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <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:scheme="https" android:host="mysitename.com" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

在打开链接之前,它会要求我打开我的应用程序,但问题是:两个应用程序将在手机任务管理器中打开(该应用程序不会在上一个正在运行的应用程序中打开):

在此输入图像描述

解决办法是什么?

小智 12

添加android:launchMode="singleTask"在 中声明的活动AndroidManifest.xml

然后,在您的活动中,您应该重写onNewIntent()方法,并且您将在那里获得参数。