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