Commit 708bc523 authored by yangwu.jia's avatar yangwu.jia

Fixed bug context is null

parent e4f8192b
......@@ -2,6 +2,7 @@ package com.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
......@@ -17,19 +18,20 @@ public class BoostPluginRegistry extends FlutterPluginRegistry {
protected WeakReference<Activity> mCurrentActivityRef;
private FlutterEngine mEngine;
private Context mContext;
public BoostPluginRegistry(FlutterEngine engine, Context context) {
super(engine, context);
mEngine = engine;
mContext=context;
}
public PluginRegistry.Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mEngine, super.registrarFor(pluginKey));
}
public void currentActivity(@Nullable Activity activity) {
mCurrentActivityRef = new WeakReference<>(activity);
}
public class BoostRegistrar implements PluginRegistry.Registrar {
......@@ -70,12 +72,12 @@ public class BoostPluginRegistry extends FlutterPluginRegistry {
@Override
public Context context() {
return mRegistrar.context();
return BoostPluginRegistry.this.mContext;
}
@Override
public Context activeContext() {
return mRegistrar.activeContext();
return BoostPluginRegistry.this.mContext;
}
@Override
......@@ -90,7 +92,7 @@ public class BoostPluginRegistry extends FlutterPluginRegistry {
@Override
public PlatformViewRegistry platformViewRegistry() {
return mRegistrar.platformViewRegistry();
return mEngine.getPlatformViewsController().getRegistry();
}
@Override
......
......@@ -44,6 +44,8 @@ public class NewFlutterBoost {
doInitialFlutterViewRun(mPlatform);
}
registry = new BoostPluginRegistry(this.engineProvider(),
mPlatform.getApplication());
platform.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
......@@ -53,7 +55,7 @@ public class NewFlutterBoost {
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
Log.e("bbbb2", "xxxxx");
registry.currentActivity(activity);
doInitialFlutterViewRun(mPlatform);
}
}
......@@ -117,8 +119,7 @@ public class NewFlutterBoost {
});
registry = new BoostPluginRegistry(this.engineProvider(),
mPlatform.getApplication());
mPlatform.registerPlugins(registry);
......
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