Custom tab does not close, different behavior for Android versions

728 views Asked by At

My app is opening a custom tab to connect to my server. My server processes user input and then returns to the app using a javascript intent and extras - the intent is set to open an activity with the needed browsable intent filter.

The browser is retaining focus. How do I get the anchor on the HTML button to correctly open the app and disappear the browser window when the user triggers the javascript Android intent with the button on the HTML page?

The behavior is not consistent. Android 4.2 can work correctly with the custom tabs while Samsung Android 6 works once and then fails when the user returns to the browser. Tabs fail in an inconsistent way on the newer versions of Android. If I disable tabs to workaround and use the system browser for Android 6, then the Android 4 system browser fails in the same way that the tabs fail. This makes me think there is some obvious gap in the html. When the javascript intent is called I see that the app getting the intent and extras -> the deep link works. The browser window, however, stays on top. Is there some trick to the HTML programming on such an intent? The user gesture is there. What else do I need? Can I leverage the callbacks and request focus?

Thanks in advance for your kind assistance.

1

There are 1 answers

1
Beth Mezias On

Turns out the issue was just that the Activity opened by the javascript intent had no UI and immediately finished. For some reason, I thought that Android would stay inside my app but the backstack just did what it usually does.

The answer was to start the app's MainActivity before finishing the activity started with the javascript intent. Finishing it without intentionally coding the app to go to another activity inside the app meant that I would return to the custom tab, return to the browser. It looked as if the browser was retaining focus when in fact the javascript intent started the activity and returned to my app but the activity finished and focus returned to the custom tab that called that activity.