Repository navigation
Support FragmentActivity for plugins #43921
Description
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
matthew-carroll commentedon Oct 31, 2019
CC @xster
acoutts commentedon Feb 10, 2020
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_storageI wanted to use that library because they use the new BiometricManager which supports face unlock in the latest Android devices.
snaeji commentedon Feb 28, 2020
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
matthew-carroll commentedon Feb 28, 2020
@snaeji can you describe why an app developer can't explicitly use a
FlutterFragmentActivityto 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."?
snaeji commentedon Feb 29, 2020
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:
matthew-carroll commentedon Feb 29, 2020
It sounds like maybe the audio_service should update to the new plugin API. Plugins should not be invoking
application.getCurrentActivity()any more.stuartmorgan-g commentedon Jul 20, 2021
Is this still relevant for the V2 embedding?
/cc @blasten
Harishwarrior commentedon Oct 4, 2021
https://stackoverflow.com/a/69432333/13389569
This is a temporary workaround for this issue. Please let me know if this can be improved further.
fix: Support FragmentActivity for plugins in Android embedding (issue f…