Reputation: 111
Context:
Our app recently switched to using Custom Chrome Tabs for authentication. WebViews wouldn't allow login from Google and Facebook due to privacy restrictions.
Everything worked well using onResume
and onNewIntent
lifecycle methods to detect when the user closes the Custom Chrome Tab and is redirected back to our app. However, a recent Chrome update introduced a minimize button (Picture-in-Picture mode) for Custom Chrome Tabs.
For our authentication flow, this minimize functionality is undesirable. We want the user to complete authentication before interacting with the app again. Unfortunately, modifying Chrome Tab behavior directly is limited due to privacy concerns.
Our current issue is that when the user minimizes the Custom Chrome Tab, our app using onResume interprets it as a complete closure. I've explored onMinimized
and onUnMinimized
APIs from CustomTabCallback, but they don't detect the scenario where the user minimizes and then closes the tab. This leaves our app's activity empty, resulting in a poor user experience.
Question:
Additional Information:
I've explored onMinimized
and onUnMinimized
APIs from CustomTabCallback
. To track the minimized state, I implemented a flag. However, this approach has limitations. Inside onResume, I use a timer (set to 750 milliseconds) to periodically check the flag. If the flag shows the tab is minimized, I avoid treating it as a closed tab. This introduces a slight delay in detecting the close event, and I'm curious if there are better solutions.
But as I said earlier this solution can resolve detecting the minimize state but when user closes the custom tab when it is in minimized state we dont have any way to detect.
Is there any way to detect the closing of custom tab in minimized state?
Thanks for any help!!
Upvotes: 11
Views: 743
Reputation: 181
According to Android documentation, and this thread of Chrome issue discussion, you can use an onSessionEnded
callback.
This callback will be executed when the Custom Chrome Tab is closed and covers the case where it has been minimized.
Apparently onSessionEnded
did not capture this case at the time this question was asked and it was fixed as a bug within a month: https://chromiumdash.appspot.com/commit/df58de7645b14f17341bbc2251c36ae1ac90d178
Upvotes: 1