FlutterFragment should support owning the engine across configuration change #94431
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
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
flutter/packages/flutter_tools/templates/app_shared/android.tmpl/app/src/main/AndroidManifest.xml.tmpl
Line 12 in 361d416
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.
The text was updated successfully, but these errors were encountered: