flutter_custom_tabs icon indicating copy to clipboard operation
flutter_custom_tabs copied to clipboard

App links and custom tabs

Open twklessor opened this issue 6 months ago • 3 comments

Hello,

Thanks for a great package!

We are observing an issue regarding App Links and Custom Tabs on Android.

The issue

We are launching a Custom Tab that through interactions ends up launching another app to do some confirmation (like a payment app or national identity app). This app then ends up launching our app again through an App Link. This causes the Custom Tab that our app opened to close so the flow cannot finish and any state that was in the Custom Tab is lost.

Simple flow;

  1. Our app launches a Custom Tab
  2. Interaction inside the Custom Tab ends up launching another app (third part payment app etc.)
  3. This third party app ends up using an App Link to our app
  4. The App Link is picked up by our app
  5. The Custom Tab disappears/closes
  6. The flow stop prematurely and cannot finish because the Custom Tab is now closed.

My hunch about the issue

The Custom Tab is launched from another Android activity than the .MainActivity where the Flutter engine is bootstrapped. This causes any App Links / Deep Links hooked to the .MainActivity using intent-filter to launch and therefore the Custom Tab disappears as it's hooked to another activity. Another possibility is the android:launchMode="singleTop" for the .MainActivity. Is there anything to my hunch and also is this a known issue?

twklessor avatar Jul 03 '25 09:07 twklessor

@twklessor Did you find a solution for this problem?

Vingtoft avatar Aug 29 '25 16:08 Vingtoft

@droibit would love your thoughts on this issue, any idea for a solution?

Vingtoft avatar Aug 29 '25 16:08 Vingtoft

@Vingtoft @droibit I have found a solution which ain't pretty but it works. Basically you have to override the onCreate in MainActivity; which will most likely be MainActivity.kt depending on your setup;

class MainActivity : FlutterFragmentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        intent.data?.let { uri ->
            /// We avoid any interaction from Flutter engine by finishing 
            /// any activity if the intent has below URI.
            /// Will keep any Custom Tabs session.
            if (uri.toString().contains("https://my-app-link.link/app-link-path")) {
                finish()
                return
            }
        }
    }
}

It would make a lot of sense to document this in the README. Without it I currently would say that Custom Tabs are not really supported together with App Links.

twklessor avatar Oct 23 '25 12:10 twklessor