Commit f0aa4aec authored by yangwu.jia's avatar yangwu.jia

解决registerPlugins 时候,必须attach activity

parent 08956ada
......@@ -12,10 +12,12 @@ import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
......@@ -27,8 +29,9 @@ public class NewFlutterBoost {
private FlutterEngine mEngine;
private Activity mCurrentActiveActivity;
private PluginRegistry mRegistry;
static NewFlutterBoost sInstance = null;
private boolean hasRegistry=false;
static NewFlutterBoost sInstance = null;
public static NewFlutterBoost instance() {
if (sInstance == null) {
......@@ -154,19 +157,11 @@ public class NewFlutterBoost {
FlutterMain.findAppBundlePath(),
"main"
);
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine());
// ((BoostPluginRegistry) mRegistry).currentActivity(mCurrentActiveActivity);
mPlatform.registerPlugins(mRegistry);
if(mPlatform.lifecycleListener!=null){
mPlatform.lifecycleListener.onPluginsRegistered();
}
}
......@@ -322,6 +317,25 @@ public class NewFlutterBoost {
}
public void registerPlugins() {
if(!hasRegistry&&mRegistry!=null){
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if(mPlatform.lifecycleListener!=null){
mPlatform.lifecycleListener.onPluginsRegistered();
}
hasRegistry=true;
}
}
public FlutterEngine engineProvider() {
return mEngine;
}
......
......@@ -34,15 +34,7 @@ public abstract class Platform {
}
public void registerPlugins(PluginRegistry registry) {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, registry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
......@@ -130,6 +130,12 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@NonNull
View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.v(TAG, "Creating FlutterView.");
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
NewFlutterBoost.instance().registerPlugins();
mSyncer = NewFlutterBoost.instance().containerManager().generateSyncer(this);
......@@ -173,10 +179,15 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed();
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
BoostPluginRegistry registry= (BoostPluginRegistry)NewFlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()!=this.host.getActivity())){
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
}
}
......
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