Skip to content

Issue with CustomTabsActivityManager and multiple activities #873

@koviant

Description

@koviant

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

  1. Download the repo
  2. Run the android app on the device that have browser, which supports CustomTabs (Chrome)
  3. Tap "Navigate to second activity" button
  4. Tap "Open Web Auth" button
  5. Verify that the CustomTab is open, user is not redirected to a browser app
  6. Go back to the repro app
  7. Tap "Go back", which would finish the second activity
  8. Tap "Navigate to second activity" button
  9. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions