Repository navigation
[shared engine][android] Unexpected behavior in detachFromFlutterEngine #94802
Copy link
Copy link
Closed
flutter-team-archive/engine
#30202Labels
engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionwaiting for PR to land (fixed)A fix is in flightA fix is in flight
Description
The behavior of the |detachFromFlutterEngine| in FlutterActivity/FlutterFragment is NOT as expected.
Please consider the following scenario where multiple FlutterActivities share one FlutterEngine (E.g, flutter_boost):
- Open page A implemented by FlutterActivity A.
- Open page B implemented by FlutterActivity B from page A. (FlutterActivity A is detached from the engine.)
- Go back to the previous page A from page B. (FlutterActivity B is detached from the engine, while FlutterActivity A is reattached.)
Actual results:
As the picture shows when a new Activity is being attached while an existing Activity is already attached, the existing Activity is disposed immediately and can't be reused anymore.
Expected results:
In the scenario of shared-engine, we expect that the detached Activity can be re-attached later instead of being disposed.
flutter doctor -v
[✓] Flutter (Channel master, 2.6.0-12.0.pre.757, on macOS 12.0.1 21A559 darwin-x64, locale zh-Hans-CN)
• Flutter version 2.6.0-12.0.pre.757 at /Users/zero/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 1ba81373ee (3 weeks ago), 2021-11-17 22:01:34 -0500
• Engine revision a3ef1d5351
• Dart version 2.16.0 (build 2.16.0-20.0.dev)
• DevTools version 2.8.0
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/zero/Library/Android/sdk
• Platform android-Sv2, build-tools 31.0.0
• ANDROID_HOME = /Users/zero/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/zero/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 12.5.1)
• Xcode at /Applications/Xcode12.5.app/Contents/Developer
! Flutter recommends a minimum Xcode version of 13.
Download the latest version or update via the Mac App Store.
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.62.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• iPhone (mobile) • 50131fb4dcef9d96405ec953e272bd5c24468370 • ios • iOS 15.0 19A346
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.55
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-androidAndroid applications specificallyAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionwaiting for PR to land (fixed)A fix is in flightA fix is in flight

Activity
[-][shared engine][android] The behavior of the detachFromFlutterEngine is not as expected[/-][+][shared engine][android] Unexpected behavior in detachFromFlutterEngine[/+]0xZOne commentedon Dec 8, 2021
An alternative solution is for the developer to implement FlutterActivity/FlutterFragment subclasses to override |detachFromFlutterEngine|.
Or In FlutterActivity/FlutterFragment subclass override |shouldAttachEngineToActivity| to return false, and call flutterEngine.getActivityControlSurface().attachToActivity/detachFromActivity at the right time and place by developer.
But, the precondition is the subclass can access FlutterActivityAndFragmentDelegate (ExclusiveAppComponent<Activity>). (Related PR: flutter-team-archive/engine#30126)
darshankawar commentedon Dec 8, 2021
@0xZOne
Can you provide us a minimal code sample representing above scenarios so that we can verify it further ?
Thanks.
0xZOne commentedon Dec 8, 2021
In fact, the conclusion can be simply obtained from the logic of the above code.
blasten commentedon Dec 8, 2021
Yes, this seems incorrect. cc @gaaclarke
github-actions commentedon Dec 24, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.