【发布时间】:2016-10-12 14:40:31
【问题描述】:
我正在开发一个具有 2 种启动方法的 android 应用程序。 一种是按手机上的应用程序图标的正常方式。 另一种方法是使用来自网站的深层链接。
深层链接还会发送一些数据,应用程序需要这些数据来做一些“事情”。然而,这应该只做一次。 深度链接活动完成后,它会启动主要活动。但是,当我按下(在设备上)并从最近打开应用程序时,它会再次打开深度链接活动。
我可以从清单中的最近更新中排除深层链接活动。这也从最近的应用程序中排除了 mainactivity,这不应该是这种情况。
如何防止深度链接活动从最近的应用程序开始?
我的清单:
<activity
android:name="MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="@style/AppTheme">
</activity>
<activity
android:name="DeeplinkActivity"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="@style/AppTheme">
<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="app_name" android:host="test" />
</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="test" android:path="/" android:scheme="app_name" />
</intent-filter>
</activity>
要切换到 MainActivity,我执行以下操作:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
编辑: 这篇文章被标记为重复:Android: Starting app from 'recent applications' starts it with the last set of extras used in an intent
但是,该帖子涉及相同的活动。我想更改根活动,因此当我从最近启动应用程序时,它不会启动 DeeplinkActivity。是的,作为一种解决方法,我可以检查 Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY 标志。但是,每次用户从最近启动应用程序时,DeeplinkActivity 都会打开,而不再需要它。
设置和/或清除其他意图值似乎不起作用。 我使用来自 getIntent().getData() 的信息
如果您仍然觉得这是重复的,请解释一下。
【问题讨论】:
-
我重新打开了这个问题。
标签: android android-activity deeplink