Welcome to reprint, and identify the source juejin.cn/post/684490…
Today I tried importing the Flutter module in a native Android project, but an exception occurred when SWITCHING FlutterFragment with FragmentManager saying “Platform view is not attached”.
(My demo is a native fragment, a FlutterFragment)
The reason was later found when we looked at the FlutterView code, before we created the FlutterView
Flutter.createView(getActivity(), getLifecycle(), mRoute)
Copy the code
Bound to an external FlutterFragment’s life cycle, this FlutterFragment naturally calls onDestroy when switching to another Framgment, The FlutterView also listens to and calls its own Destroy via getLifecycle and destroys the parasitic external mNativeView. An exception is caused because mNativeView is empty
public void destroy() {
if(this.isAttached()) { this.getHolder().removeCallback(this.mSurfaceCallback); this.mNativeView.destroy(); this.mNativeView = null; }}Copy the code
The root cause is that my FlutterFragment did not trigger onCreateView, causing Flutter.createView(getActivity(), getLifecycle(), mRoute).
No execution.