简体   繁体   English

关闭Chrome自定义标签的回调

[英]Callback on dismiss of chrome custom tabs

I have an activity 'A' and inside that activity, I have opened a chrome custom tab. 我有一个活动'A',在该活动中,我打开了一个chrome自定义标签。 Now when the user closes the chrome custom tab I want to open another activity 'B'. 现在,当用户关闭chrome自定义选项卡时,我想打开另一个活动“B”。 Is there a way to know when the chrome custom tabs has been closed. 有没有办法知道Chrome自定义标签何时关闭。 Or any other way to solve the above problem. 或任何其他方式来解决上述问题。

In Activity A you launch the Chrome Custom Tab like this: 在活动A中,您可以像这样启动Chrome自定义标签:

private final int CHROME_CUSTOM_TAB_REQUEST_CODE = 100;

public void launchCustomTabs(String url) {
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.intent.setData(Uri.parse(url));
    startActivityForResult(customTabsIntent.intent, CHROME_CUSTOM_TAB_REQUEST_CODE);
}

And in onActivityResult your check for that request code: 在onActivityResult中,您检查该请求代码:

if (requestCode == CHROME_CUSTOM_TAB_REQUEST_CODE) {
    startActivity(this, ActivityB.class);
}

You could keep track that Custom Tabs was opened on a boolean variable on Activity A. 您可以跟踪在活动A上的布尔变量上打开自定义选项卡。

private boolean mCustomTabsOpened = false;

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

Then, use Activity A's onResume() to launch Activity B 然后,使用Activity A的onResume()来启动Activity B.

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

You may want to use the KeepAliveService to prevent ActivityA from being destroyed, as illustrated here 您可能需要使用KeepAliveService防止ActivityA被破坏,如图所示这里

well, this doesn't work, because it's not possible as per now to track the closing of chrome custom tab, if you are trying to call or display a dialog box on hit of back button, ie, to ask for a confirmation. 好吧,这不起作用,因为现在跟踪Chrome自定义选项卡的关闭是不可能的,如果你试图在后退按钮上调用或显示一个对话框,即要求确认。 Well you can handle them over your activity (which is launching it at the first place) but that's not what you want i think. 那么你可以通过你的活动来处理它们(这是在第一个位置启动它)但是这不是你想要的。 But if anyone does find the solution then please comment below. 但如果有人确实找到了解决方案,那么请在下面评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM