Callback on dismiss of chrome custom tabs

rahulk9 picture rahulk9 · Dec 7, 2016 · Viewed 10.4k times · Source

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.

Answer

Claus Holst picture Claus Holst · Jan 3, 2017

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