Commit 8dd58ee9 authored by 李增强's avatar 李增强

修复activity插件异常问题

parent 5d638134
...@@ -2,15 +2,19 @@ package com.idlefish.flutterboost.containers; ...@@ -2,15 +2,19 @@ package com.idlefish.flutterboost.containers;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.view.*; import android.view.*;
import java.io.Serializable; import java.io.Serializable;
...@@ -23,12 +27,14 @@ import com.idlefish.flutterboost.FlutterBoost; ...@@ -23,12 +27,14 @@ import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Utils; import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.idlefish.flutterboost.interfaces.IOperateSyncer; import com.idlefish.flutterboost.interfaces.IOperateSyncer;
import io.flutter.Log; import io.flutter.Log;
import io.flutter.app.FlutterActivity; import io.flutter.app.FlutterActivity;
import io.flutter.embedding.android.*; import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.plugins.PluginRegistry;
import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.plugin.platform.PlatformPlugin;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
...@@ -37,7 +43,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -37,7 +43,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
private static final String TAG = "FlutterActivityAndFragmentDelegate"; private static final String TAG = "FlutterActivityAndFragmentDelegate";
private static int ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE=0; private static int ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE = 0;
@NonNull @NonNull
private Host host; private Host host;
@Nullable @Nullable
...@@ -179,20 +185,18 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -179,20 +185,18 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
public void onResume() { public void onResume() {
if(mSyncer.isLocked()) return; if (mSyncer.isLocked()) return;
mSyncer.onAppear(); mSyncer.onAppear();
Log.v(TAG, "onResume()"); Log.v(TAG, "onResume()");
ensureAlive(); ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed(); flutterEngine.getLifecycleChannel().appIsResumed();
if(ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE == 0 || if (ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE == 0 ||
ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE != this.host.getActivity().hashCode()){ ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE != this.host.getActivity().hashCode()) {
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
flutterEngine.getActivityControlSurface().attachToActivity(host.getActivity(),host.getLifecycle());
ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE = host.getActivity().hashCode(); ACTIVITY_CONTROL_SURFACE_ATTACH_TO_ACTVITY_HASH_CODE = host.getActivity().hashCode();
}
}
} }
...@@ -213,7 +217,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -213,7 +217,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
public void onPause() { public void onPause() {
Log.v(TAG, "onPause()"); Log.v(TAG, "onPause()");
if(mSyncer.isLocked()) return; if (mSyncer.isLocked()) return;
ensureAlive(); ensureAlive();
mSyncer.onDisappear(); mSyncer.onDisappear();
flutterEngine.getLifecycleChannel().appIsInactive(); flutterEngine.getLifecycleChannel().appIsInactive();
...@@ -249,7 +253,8 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -249,7 +253,8 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
if (host.getActivity().isChangingConfigurations()) { if (host.getActivity().isChangingConfigurations()) {
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges(); flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
} else { } else {
flutterEngine.getActivityControlSurface().detachFromActivity(); // flutterEngine.getActivityControlSurface().detachFromActivity();
} }
} }
Utils.fixInputMethodManagerLeak(host.getActivity()); Utils.fixInputMethodManagerLeak(host.getActivity());
...@@ -360,7 +365,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -360,7 +365,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
* <p> * <p>
* An {@code IllegalStateException} is thrown if this delegate has been {@link #release()}'ed. * An {@code IllegalStateException} is thrown if this delegate has been {@link #release()}'ed.
*/ */
private void ensureAlive() { private void ensureAlive() {
if (host == null) { if (host == null) {
throw new IllegalStateException("Cannot execute method on a destroyed FlutterActivityAndFragmentDelegate."); throw new IllegalStateException("Cannot execute method on a destroyed FlutterActivityAndFragmentDelegate.");
} }
...@@ -481,6 +486,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -481,6 +486,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
*/ */
PlatformPlugin providePlatformPlugin( PlatformPlugin providePlatformPlugin(
@Nullable Activity activity, @NonNull FlutterEngine flutterEngine); @Nullable Activity activity, @NonNull FlutterEngine flutterEngine);
/** /**
* Hook for the host to configure the {@link FlutterEngine} as desired. * Hook for the host to configure the {@link FlutterEngine} as desired.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment