Class FlutterFragmentActivity

    • Field Detail


        public static final int FRAGMENT_CONTAINER_ID
    • Constructor Detail

      • FlutterFragmentActivity

        public FlutterFragmentActivity()
    • Method Detail

      • createDefaultIntent

        public static Intent createDefaultIntent​(@NonNull
                                                 Context launchContext)
        Creates an Intent that launches a FlutterFragmentActivity, which executes a main() Dart entrypoint, and displays the "/" route as Flutter's initial route.
      • onCreate

        protected void onCreate​(@Nullable
                                Bundle savedInstanceState)
        onCreate in class
      • createFlutterFragment

        protected FlutterFragment createFlutterFragment()
        Creates the instance of the FlutterFragment that this FlutterFragmentActivity displays.

        Subclasses may override this method to return a specialization of FlutterFragment.

      • onPostResume

        public void onPostResume()
        onPostResume in class
      • onNewIntent

        protected void onNewIntent​(@NonNull
                                   Intent intent)
        onNewIntent in class
      • onBackPressed

        public void onBackPressed()
        onBackPressed in class androidx.activity.ComponentActivity
      • onRequestPermissionsResult

        public void onRequestPermissionsResult​(int requestCode,
                                               String[] permissions,
                                               int[] grantResults)
        Specified by:
        onRequestPermissionsResult in interface
        onRequestPermissionsResult in class
      • onActivityResult

        protected void onActivityResult​(int requestCode,
                                        int resultCode,
                                        Intent data)
        onActivityResult in class
      • getFlutterEngine

        protected FlutterEngine getFlutterEngine()
      • shouldDestroyEngineWithHost

        public boolean shouldDestroyEngineWithHost()
        Returns false if the FlutterEngine backing this FlutterFragmentActivity should outlive this FlutterFragmentActivity, or true to be destroyed when the FlutterFragmentActivity is destroyed.

        The default value is true in cases where FlutterFragmentActivity created its own FlutterEngine, and false in cases where a cached FlutterEngine was provided.

      • shouldAttachEngineToActivity

        protected boolean shouldAttachEngineToActivity()
        Hook for subclasses to control whether or not the FlutterFragment within this Activity automatically attaches its FlutterEngine to this Activity.

        For an explanation of why this control exists, see FlutterFragment.shouldAttachEngineToActivity().

        This property is controlled with a protected method instead of an Intent argument because the only situation where changing this value would help, is a situation in which FlutterFragmentActivity is being subclassed to utilize a custom and/or cached FlutterEngine.

        Defaults to true.

      • shouldHandleDeeplinking

        protected boolean shouldHandleDeeplinking()
        Whether to handle the deeplinking from the Intent automatically if the getInitialRoute returns null.

        The default implementation looks <meta-data> called FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY within the Android manifest definition for this FlutterFragmentActivity.

      • provideFlutterEngine

        public FlutterEngine provideFlutterEngine​(@NonNull
                                                  Context context)
        Hook for subclasses to easily provide a custom FlutterEngine.
        Specified by:
        provideFlutterEngine in interface FlutterEngineProvider
        context - The current context. e.g. An activity.
        The Flutter engine.
      • configureFlutterEngine

        public void configureFlutterEngine​(@NonNull
                                           FlutterEngine flutterEngine)
        Hook for subclasses to easily configure a FlutterEngine.

        This method is called after provideFlutterEngine(Context).

        All plugins listed in the app's pubspec are registered in the base implementation of this method unless the FlutterEngine for this activity was externally created. To avoid the automatic plugin registration for implicitly created FlutterEngines, override this method without invoking super(). To keep automatic plugin registration and further configure the FlutterEngine, override this method, invoke super(), and then configure the FlutterEngine as desired.

        Specified by:
        configureFlutterEngine in interface FlutterEngineConfigurator
        flutterEngine - The Flutter engine.
      • getAppBundlePath

        protected String getAppBundlePath()
        A custom path to the bundle that contains this Flutter app's resources, e.g., Dart code snapshots.

        When this FlutterFragmentActivity is run by Flutter tooling and a data String is included in the launching Intent, that data String is interpreted as an app bundle path.

        When otherwise unspecified, the value is null, which defaults to the app bundle path defined in FlutterLoader.findAppBundlePath().

        Subclasses may override this method to return a custom app bundle path.

      • getDartEntrypointFunctionName

        public String getDartEntrypointFunctionName()
        The Dart entrypoint that will be executed as soon as the Dart snapshot is loaded.

        This preference can be controlled by setting a <meta-data> called FlutterActivityLaunchConfigs.DART_ENTRYPOINT_META_DATA_KEY within the Android manifest definition for this FlutterFragmentActivity.

        Subclasses may override this method to directly control the Dart entrypoint.

      • getDartEntrypointArgs

        public List<String> getDartEntrypointArgs()
        The Dart entrypoint arguments will be passed as a list of string to Dart's entrypoint function.

        A value of null means do not pass any arguments to Dart's entrypoint function.

        Subclasses may override this method to directly control the Dart entrypoint arguments.

      • getDartEntrypointLibraryUri

        public String getDartEntrypointLibraryUri()
        The Dart library URI for the entrypoint that will be executed as soon as the Dart snapshot is loaded.

        Example value: "package:foo/bar.dart"

        This preference can be controlled by setting a <meta-data> called FlutterActivityLaunchConfigs.DART_ENTRYPOINT_URI_META_DATA_KEY within the Android manifest definition for this FlutterFragmentActivity.

        A value of null means use the default root library.

        Subclasses may override this method to directly control the Dart entrypoint uri.

      • getInitialRoute

        protected String getInitialRoute()
        The initial route that a Flutter app will render upon loading and executing its Dart code.

        This preference can be controlled with 2 methods:

        1. Pass a boolean as FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE with the launching Intent, or
        2. Set a <meta-data> called FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY for this Activity in the Android manifest.
        If both preferences are set, the Intent preference takes priority.

        The reason that a <meta-data> preference is supported is because this Activity might be the very first Activity launched, which means the developer won't have control over the incoming Intent.

        Subclasses may override this method to directly control the initial route.

        If this method returns null and the shouldHandleDeeplinking returns true, the initial route is derived from the Intent through the Intent.getData() instead.

      • getCachedEngineId

        protected String getCachedEngineId()
        Returns the ID of a statically cached FlutterEngine to use within this FlutterFragmentActivity, or null if this FlutterFragmentActivity does not want to use a cached FlutterEngine.
      • getCachedEngineGroupId

        protected String getCachedEngineGroupId()
      • provideRootLayout

        protected FrameLayout provideRootLayout​(Context context)
        Returns a FrameLayout that is used as the content view of this activity.