There's a callback when you bind a custom tab service that will alert you when a tab is shown (5) / hidden (6)
CustomTabsServiceConnection customTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
client = customTabsClient;
client.warmup(0L);
customTabsSession = client.newSession(new CustomTabsCallback() {
@Override
public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) {
super.onNavigationEvent(navigationEvent, extras);
}
}
}
You can then bind this and the callbacks will start triggering when you use it when launching your tabs (SDK <= 29, it will be different on 30)
String packageName = CustomTabsClient.getPackageName(this, null);
boolean didSucceed = CustomTabsClient.bindCustomTabsService(this, packageName, mCustomTabsServiceConnection);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(customTabsSession);