Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
.NET 7.0.404, .NET 8.0.200
Description
Hello,
I'd like to report an issue that I've encountered while using WebAuthenticator from the MAUI Essentials.
In order to open the link in the CustomTabs on Android, WebAuthenticator uses the CustomTabsActivityManager from the Xamarin.AndroidX.Browser nuget. Method CustomTabsActivityManager.From contains the following code:
static CustomTabsActivityManager instance;
public static CustomTabsActivityManager From(Activity parentActivity, string servicePackageName = null)
{
if (instance == null) {
instance = new CustomTabsActivityManager(parentActivity);
}
return instance;
}
Due to the static instance field of the manager, it forever holds the reference to the activity that was passed with the first call to that method. The problem happens when this activity was destroyed, and then the app tries to call WebAuthenticator again. CustomTabsActivityManager still holds the reference to the Activity that is no longer in use, and then WebAuthenticator fails to use CustomTabs and fallbacks to the default browser.
I've created a repo where you can reproduce the issue.
Thank you
Steps to Reproduce
- Download the repo
- Run the android app on the device that have browser, which supports CustomTabs (Chrome)
- Tap "Navigate to second activity" button
- Tap "Open Web Auth" button
- Verify that the CustomTab is open, user is not redirected to a browser app
- Go back to the repro app
- Tap "Go back", which would finish the second activity
- Tap "Navigate to second activity" button
- Tap "Open Web Auth" button
Expected result: link is still opened in the CustomTabs
Actual result: user is redirected to the browser app, CustomTabs are not open
Did you find any workaround?
Haven't found a workaround, except copying all the code from MAUI's WebAuthenticator and from AndroidX.Browser, and changing the code in the CustomTabsActivityManager.From, so that it would check that passed activity is not the same as the one it already holds.
Relevant log output
No response
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
.NET 7.0.404, .NET 8.0.200
Description
Hello,
I'd like to report an issue that I've encountered while using
WebAuthenticatorfrom the MAUI Essentials.In order to open the link in the CustomTabs on Android,
WebAuthenticatoruses theCustomTabsActivityManagerfrom the Xamarin.AndroidX.Browser nuget. MethodCustomTabsActivityManager.Fromcontains the following code:Due to the static instance field of the manager, it forever holds the reference to the activity that was passed with the first call to that method. The problem happens when this activity was destroyed, and then the app tries to call WebAuthenticator again. CustomTabsActivityManager still holds the reference to the Activity that is no longer in use, and then WebAuthenticator fails to use CustomTabs and fallbacks to the default browser.
I've created a repo where you can reproduce the issue.
Thank you
Steps to Reproduce
Expected result: link is still opened in the CustomTabs
Actual result: user is redirected to the browser app, CustomTabs are not open
Did you find any workaround?
Haven't found a workaround, except copying all the code from MAUI's WebAuthenticator and from AndroidX.Browser, and changing the code in the
CustomTabsActivityManager.From, so that it would check that passed activity is not the same as the one it already holds.Relevant log output
No response