From 96ef7f6c1a81b9b42dbe5c32b96f996eb3f1b7f4 Mon Sep 17 00:00:00 2001 From: Ali Bitek Date: Sat, 20 Jan 2018 09:46:40 +0200 Subject: [PATCH] Get active Context from the Registrar (flutter/engine#4523) --- engine/src/flutter/AUTHORS | 1 + .../android/io/flutter/app/FlutterPluginRegistry.java | 5 +++++ .../android/io/flutter/plugin/common/PluginRegistry.java | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/engine/src/flutter/AUTHORS b/engine/src/flutter/AUTHORS index 35a541722b..6574dff16b 100644 --- a/engine/src/flutter/AUTHORS +++ b/engine/src/flutter/AUTHORS @@ -5,3 +5,4 @@ Google Inc. Jim Simon +Ali Bitek diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java index b4cde77021..9991d98d27 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java @@ -92,6 +92,11 @@ public class FlutterPluginRegistry return mAppContext; } + @Override + public Context activeContext() { + return (mActivity != null) ? mActivity : mAppContext; + } + @Override public BinaryMessenger messenger() { return mNativeView; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java index d06e64183c..855377bea7 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java @@ -80,6 +80,13 @@ public interface PluginRegistry { */ Context context(); + /** + * Returns the active {@link Context}. + * + * @return the current {@link #activity() Activity}, if not null, otherwise the {@link #context() Application}. + */ + Context activeContext(); + /** * Returns a {@link BinaryMessenger} which the plugin can use for * creating channels for communicating with the Dart side.