Closed koviant closed 2 months ago
I suspect anyone who knows why this was written this way is long gone.
However, CustomTabsActivityManager
has a public constructor:
public CustomTabsActivityManager (Activity parentActivity)
{
ParentActivity = parentActivity;
}
You should be able to create whatever CustomTabsActivityManager
instances you want and managed their lifetimes however you see fit without using the From
method.
Thanks, that should work. I guess now I should head out to the MAUI repo and ask them to drop calling the From
method in favor of that constructor.
Btw, if you don't mind, I would like make a PR adding an [Obsolete] attribute on the From
method, so that in future there would be less chance that someone would use this method, with the message that it may cause a memory leak by holding the reference to the activity in the static instance field.
Agreed, I was thinking the same thing. 😉
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 theCustomTabsActivityManager
from the Xamarin.AndroidX.Browser nuget. MethodCustomTabsActivityManager.From
contains 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