拦截点击 URL 打开超过 1 个实例

Intercepting clicked URL opening more than 1 instance

我正在尝试拦截点击 URL 打开我的 APP

<intent-filter>
    <data
        android:host="myurl.open"
        android:path="/import"
        android:scheme="http" />

        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

在MainActivity

String linkClicked = getIntent().getDataString();
new AlertDialog.....

它几乎可以正常工作,但问题是:

Every new clicked link it open a new instance of my app, but I don't want this, I want it to display in the same opened instance

示例:

点击我的网址。open/import?=1

打开显示用户在 link

中单击的对话框的第一个实例

点击我的网址。open/import?=2

打开第一个实例并显示显示新单击 URL 的对话框,但它打开了一个新实例,所以我现在有 2 运行 个 apk,如果我单击第三个 link它会打开第三个,我怎样才能让它只打开一样?

如果我再次单击同一个 URL,它会打开从这个 URL 打开的第一个实例,但不会显示 AlertDialog

1) 要打开应用程序的单个实例,请在 activity 标签的 AndroidManifest.xml 中使用 android:launchMode="singleTask"android:launchMode="singleInstance"

2) 要从新意图中获取数据,只需覆盖 onNewIntent() 方法:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); // to attach the new intent to your Activity
    //now getIntent() will return the last data
}