Get active Context from the Registrar (flutter/engine#4523)

This commit is contained in:
Ali Bitek
2018-01-20 09:46:40 +02:00
committed by Mikkel Nygaard Ravn
parent d595980338
commit 96ef7f6c1a
3 changed files with 13 additions and 0 deletions

View File

@@ -5,3 +5,4 @@
Google Inc.
Jim Simon <jim.j.simon@gmail.com>
Ali Bitek <alibitek@protonmail.ch>

View File

@@ -92,6 +92,11 @@ public class FlutterPluginRegistry
return mAppContext;
}
@Override
public Context activeContext() {
return (mActivity != null) ? mActivity : mAppContext;
}
@Override
public BinaryMessenger messenger() {
return mNativeView;

View File

@@ -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.