Skip to content

Support FragmentActivity for plugins #43921

Open

Description

@matthew-carroll

This is a documentation ticket that explains why FragmentActivity is not currently supported for plugin access. Other tickets that reference this limitation can link to this one, and developers can thumbs up this issue if they run into use-cases that are significantly hampered by the lack of FragmentActivity support.

Why not make FlutterActivity a FragmentActivity in all cases?

Flutter's use of FragmentActivity requires the inclusion of the Fragment support library. The Fragment support library adds a 100k binary size increase (when optimized). Most full-Flutter apps do not require any use of Fragments, making that 100k binary size increase unnecessary. Therefore, a standard Flutter project uses FlutterActivity, which extends a regular Activity.

A FlutterFragmentActivity is made available within the Android embedding for those projects that require a FragmentActivity. However, the ActivityAware plugin API only exposes a regular Activity via getActivity(). This is because the only thing the embedding knows for sure is that an Activity is available, but not necessarily a FragmentActivity.

Some plugins really do require a FragmentActivity. The current solution for those plugins is to attempt to cast the Activity to a FragmentActivity. It then becomes the responsibility of the app developer to manually switch from FlutterActivity to FlutterFragmentActivity.

This ticket exists to collect issues and concerns about this approach. If a strong enough argument is made to add some kind of support for FragmentActivity exposure in the plugin APIs then the ecosystem team and the embedding team should work together to design the appropriate solution.

Activity

  1. matthew-carroll commented on Oct 31, 2019

    @matthew-carroll
    ContributorAuthor
  2. acoutts commented on Feb 10, 2020

    @acoutts

    The use of biometrics is a good use case for this. It looks like this library no longer works with the new ActivityAware: https://github.com/authpass/biometric_storage

    I wanted to use that library because they use the new BiometricManager which supports face unlock in the latest Android devices.

  3. snaeji commented on Feb 28, 2020

    @snaeji

    In my opinion the lack of support for FragmentedActivity is forcing people to choose between subset of packages. For example using the audio_service package and local_auth together is not possible. Changing FlutterActivity to FlutterFragmentedActivity for plugins that require it results in other plugins failing.

    ryanheise/audio_service#87

  4. matthew-carroll commented on Feb 28, 2020

    @matthew-carroll
    ContributorAuthor

    @snaeji can you describe why an app developer can't explicitly use a FlutterFragmentActivity to resolve the issue you're disussing?

    Also, can you provide examples where "Changing FlutterActivity to FlutterFragmentActivity for plugins that require it results in other plugins failing."?

  5. snaeji commented on Feb 29, 2020

    @snaeji

    I cannot reproduce this issue and everything is working great on the latest stable Flutter release. Thanks 👍

    @matthew-carroll i was having this issue in end of September 2019. The audio_service package was throwing a null error when caling application.getCurrentActivity().

    From the audio_service issue linked in my last comment:

    It could be that application.getCurrentActivity() simply doesn't work (returns null) when you're using a FlutterFragmentActivity, and if that is the case, there's unfortunately nothing I can do on my end, and yes, it may be necessary to raise the issue with the Google team.

  6. matthew-carroll commented on Feb 29, 2020

    @matthew-carroll
    ContributorAuthor

    It sounds like maybe the audio_service should update to the new plugin API. Plugins should not be invoking application.getCurrentActivity() any more.

  7. stuartmorgan-g commented on Jul 20, 2021

    @stuartmorgan-g
    Contributor

    Is this still relevant for the V2 embedding?

    /cc @blasten

  8. added
    P3Issues that are less important to the Flutter project
    on Aug 17, 2021
  9. Harishwarrior commented on Oct 4, 2021

    @Harishwarrior
    Contributor

    https://stackoverflow.com/a/69432333/13389569

    This is a temporary workaround for this issue. Please let me know if this can be improved further.

  10. added
    engineflutter/engine related. See also e: labels.
    a: pluginsSupport for writing, building, and running plugin packages
    and removed on Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: pluginsSupport for writing, building, and running plugin packagesengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions