我从我的活动中调用了 Chrome 自定义标签页,我希望能够在我的自定义标签页上打开某个页面后返回我的应用,而无需用户点击"X"按钮。
为此,我在活动(调用自定义选项卡的活动相同(上添加了一个 Intent 过滤器,当打开该页面时,它会重定向到我的应用程序上的该活动。
现在的问题是,自定义选项卡保留在顶部。如果我手动关闭自定义选项卡,我确实会看到活动已收到响应并按预期工作,但我的活动没有出现在前台。
任何想法为什么会发生这种情况,以及解决这个问题的任何方法?
我知道到目前为止,无法以编程方式关闭自定义选项卡。我想做的只是将自定义选项卡发送到后台并将我的活动带到顶部。
我的自定义选项卡调用代码:
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(getToolBarColor())
.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
我的活动清单:
<activity
android:name="com.xyz.sdk.SomeActivity"
android:allowTaskReparenting="true"
android:configChanges="keyboardHidden|orientation|keyboard|screenSize"
android:launchMode="singleTask"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<data android:scheme="someString-${applicationId}" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
在活动中检测到相应网页时,请尝试将活动记录放在顶部(而不是后台的 Chrome 自定义标签页(,如下所示:
// Launch activity again
Intent intent = new Intent(this, A.class);
// Setting CLEAR_TOP ensures that all other activities on top of A will be finished
// and setting SINGLE_TOP ensures that a new instance of A will not
// be created (the existing instance will be reused and onNewIntent() will be called)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);