Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlutterFragment should support owning the engine across configuration change #94431

Open
xster opened this issue Nov 30, 2021 · 0 comments
Open
Labels
c: new feature Nothing broken; request for a new capability customer: google Various Google teams engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@xster
Copy link
Member

xster commented Nov 30, 2021

Currently, the FlutterFragment can create and own its own engine or have one injected into it.

The FlutterFragment creating its own engine can have a problem when the engine should outlive the instance of the FlutterFragment. This can happen on configuration change (https://developer.android.com/guide/topics/resources/runtime-changes) such as rotating the screen. When the FlutterFragment is destroyed and recreating with the new configuration, the same FlutterEngine instance should be preserved.

This isn't a problem generally because we instruct Android to not change configuration on the FlutterActivity

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
. But this isn't possible in hybrid apps where native UI also exist alongside the FlutterFragment. In that case, the native UI relies on the other fragments in the activity being destroyed and recreated to adjust to the new configuration. But the FlutterFragment should be destroyed and recreated with the FlutterEngine it owns also being destroyed and recreated.

This can be done either by temporarily saving the owned FlutterEngine instance in the FlutterEngineCache or by using Android's https://developer.android.com/reference/androidx/lifecycle/ViewModel mechanism, as long as that AndroidX mechanism is already part of the Flutter engine https://github.com/flutter/engine/blob/master/tools/androidx/files.json#L3 and we're not paying more size cost for it.

@xster xster added platform-android Android applications specifically engine flutter/engine repository. See also e: labels. customer: google Various Google teams labels Nov 30, 2021
@chinmaygarde chinmaygarde added P3 Issues that are less important to the Flutter project c: new feature Nothing broken; request for a new capability labels Dec 6, 2021
@xster xster added P2 Important issues not at the top of the work list and removed P3 Issues that are less important to the Flutter project labels Dec 13, 2021
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability customer: google Various Google teams engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests

4 participants