发送 Chrome 个自定义标签到后台

Send Chrome custom tab to background

我从我的 activity 中调用了一个 Chrome 自定义选项卡,我希望在我的自定义选项卡上打开某个页面后无需用户点击就可以返回到我的应用程序在 "X" 按钮上。

为此,我在 activity 上添加了一个意图过滤器(与调用自定义选项卡的 activity 相同),当该页面打开时,它会重定向到 activity 在我的应用程序上。

现在的问题是,自定义选项卡位于顶部。如果我手动关闭我的自定义选项卡,我确实看到 activity 已收到响应并按预期工作,但我的 activity 没有出现在前台。

知道为什么会这样吗?有什么办法可以解决这个问题?

我知道目前无法以编程方式关闭自定义选项卡。我想要做的就是将自定义选项卡发送到后台并将我的 activity 置于顶部。

我的自定义标签调用代码:

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 清单:

<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>

检测 activity 中的页面时,尝试将 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);