深层链接和多个应用程序实例 [英] Deep linking and multiple app instances

查看:101
本文介绍了深层链接和多个应用程序实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中实现了深层链接.我在清单文件中添加了这个意图过滤器,并且深层链接正在工作.

I have implemented deep linking in my app. I added this intent filter in my manifest file, and the deep linking is working.

<intent-filter>
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <category android:name="android.intent.category.VIEW" /> 
    <data
        android:host="www.mywebsite.com"
        android:pathPrefix="/something"
        android:scheme="http" />
</intent-filter>

问题在于,通过深层链接,我的应用程序正在当前应用程序之上启动.如果我在Gmail中并单击链接,则表明我的应用程序正在Gmail之上启动.我想以不同的方式启动我的应用.

The problem is that through deep linking, my app is launching on top of current app. If I am in Gmail and I click a link, then my app is launching on top of Gmail. I want to launch my app differently.

如果我的应用程序已经在后台运行,并且我单击了Gmail中的链接并重定向到我的应用程序,则我的应用程序将同时运行两个实例;一个在后台,另一个在Gmail顶部.我一次只想运行一个应用程序实例,因此它不在当前应用程序(Gmail)之上.我该怎么办?

If my app is already running in background and I click on a link in Gmail which redirects to my app, I will have two instances of my app running at the same time; one in the background, and another on top of Gmail. I want to run only one instance of my app at a time, so it's not also on top of the current app (Gmail). How can I do that?

推荐答案

已接受的答案对我不起作用,这是做什么的:

the accepted answer didn't work for me, here is what did:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();

来自官方文档:

如果已设置,并且正在启动的活动已经在当前任务中运行,那么与其启动该活动的新实例,不如关闭该活动之上的所有其他活动,并将此Intent传递给(现在位于最前面)旧活动作为新的Intent.

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

这篇关于深层链接和多个应用程序实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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