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

fix: 修复某些机型会导致生命周期丢失 #168

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FlutterOpenimSdkPlugin implements FlutterPlugin, MethodCallHandler,
private ConnectivityListener connectivityListener;
private VisibilityListener visibilityListener;
public static boolean isInitialized;
private FlutterPluginBinding flutterPluginBinding;

public FlutterOpenimSdkPlugin() {
FlutterOpenimSdkPlugin.imManager = new IMManager();
Expand All @@ -60,44 +61,60 @@ public FlutterOpenimSdkPlugin() {

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), CHANNEL_NAME);
this.flutterPluginBinding = flutterPluginBinding;

context = flutterPluginBinding.getApplicationContext();
channel.setMethodCallHandler(this);
connectivityListener = new ConnectivityListener(context);
visibilityListener = new VisibilityListener();
connectivityListener.register();
}

private void registerMethodChannel() {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), CHANNEL_NAME);
channel.setMethodCallHandler(this);
}

private void unregisterMethodChannel() {
channel.setMethodCallHandler(null);
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
parse(call, result);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
FlutterOpenimSdkPlugin.channel.setMethodCallHandler(null);
connectivityListener.unregisterReceiver();
}


@Override
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
registerMethodChannel();

visibilityListener.register(activity = binding.getActivity());
}

@Override
public void onDetachedFromActivityForConfigChanges() {
unregisterMethodChannel();

visibilityListener.unregisterReceiver(activity);
activity = null;
}

@Override
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
registerMethodChannel();

visibilityListener.register(activity = binding.getActivity());
}

@Override
public void onDetachedFromActivity() {
unregisterMethodChannel();

visibilityListener.unregisterReceiver(activity);
activity = null;
}
Expand Down