取消启用Chrome自定义标签后的回调 [英] Callback on dismiss of chrome custom tabs

查看:114
本文介绍了取消启用Chrome自定义标签后的回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动"A",并且在该活动中,我打开了一个chrome自定义标签.现在,当用户关闭chrome自定义标签时,我想打开另一个活动"B".有没有办法知道chrome自定义标签何时关闭.或其他解决上述问题的方法.

I have an activity 'A' and inside that activity, I have opened a chrome custom tab. Now when the user closes the chrome custom tab I want to open another activity 'B'. Is there a way to know when the chrome custom tabs has been closed. Or any other way to solve the above problem.

推荐答案

您可以跟踪在活动A"上的布尔变量上打开了自定义标签".

You could keep track that Custom Tabs was opened on a boolean variable on Activity A.

private boolean mCustomTabsOpened = false;

public void launchCustomTabs(String url) {
   mCustomTabsOpened = true;
   new CustomTabs.Builder().build().launchUrl(this, Uri.parse(url));
}

然后,使用活动A的onResume()启动活动B

Then, use Activity A's onResume() to launch Activity B

public void onResume() {
    if (mCustomTabsOpened) {
        mCustomTabsOpened = false;
        startActivity(this, ActivityB.class);
    }
}

您可能希望使用KeepAliveService防止ActivityA被破坏,如下所示

You may want to use the KeepAliveService to prevent ActivityA from being destroyed, as illustrated here

这篇关于取消启用Chrome自定义标签后的回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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