Reputation: 101
I am using Chrome custom tabs for opening links inside the app. The app runs in a single activity with launchMode = singleTask. When I exit the app when the custom tab is open, and return to the app via recent apps screen, the tab is retained. However, if I exit the app and re-open it by clicking the icon on home screen launcher, the custom tab is gone.
Making some user flows such as bank payment confirmation with separate apps work is hard with this behaviour. Is there any way to retain the custom tab as long as the app is alive in background?
Code that opens the custom tab in an activity:
val builder = CustomTabsIntent.Builder()
builder.enableUrlBarHiding()
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
customTabsIntent.launchUrl(this, Uri.parse(url))
Upvotes: 2
Views: 2326
Reputation: 101
Managed to solve this myself, and it was about launchModes after all. I have a SplashActivity that is the entry point to the app (handles the MAIN and LAUNCHER intents). Then I have the MainActivity that hosts the actual app. Launchmodes were originally set up like this:
I need to keep MainActivity as singleTask, but it turned out that removing the launchMode from the SplashActivity fixed the issue. So I guess that when clicking the icon from launcher the SplashActivity was switched on top for a brief moment, which killed the Chrome custom tab.
Upvotes: 3