AgoraIO-Extensions / iris_method_channel_flutter

iris_method_channel is a method channel that communicate between C/C++(iris) and dart, which is used by Agora Flutter SDKs.
MIT License
2 stars 3 forks source link

fix: [android] Bound the IrisMethodChannel lifecycle with the FlutterEngine #75

Closed littleGnAl closed 1 year ago

littleGnAl commented 1 year ago

At this time, if the IrisMethodChannel.dispose not be called explicitly, the native resources created (created via NativeBindingDelegate.createNativeApiEngine) by the IrisMethodChannel can not be cleaned. So the native resources only be cleaned when the APP process is killed.

But by default, the FlutterEngine lifecycle is bound to the android Activity lifecycle. In the single Flutter APP, the FlutterEngine is killed when the whole APP exit(the Activity.onDestory has been called), at this time, the whole APP exit, and the APP process has been killed, so the native resources created by the IrisMethodChannel can be cleaned depending on the process lifecycle.

But in some scenarios, say that start a foreground service in android, when you try to remove the APP from the recent list, the Activity has been removed, the FlutterEngine has been destroyed, but the APP still running (the process not be killed), which will cause the memory leak, and unexpected behavior.

So we need to notify the IrisMethodChannel(dart side) to clean the native resources when the FlutterEngine is destroyed.