Callback on dismiss of chrome custom tabs

放肆的年华 提交于 2019-11-28 10:25:11

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));
}

Then, use Activity A's onResume() to launch 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

In Activity A you launch the Chrome Custom Tab like this:

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:

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

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, i.e., to ask for a confirmation. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!