Skip to content

[flutter_plugin_android_lifecycle] Add a getter for a service lifecycle #43741

@amirh

Description

@amirh

Currently the plugin only exposes a getter for the activity lifecycle, a getter for the lifecycle available through ServicePluginBinding should be added as well.

The code should be just:

  @Nullable
  public static Lifecycle getServiceLifecycle(@NonNull ServicePluginBinding servicePluginBinding) {
    try {
      Method getLifecycle = ServicePluginBinding.class.getMethod("getLifecycle");
      Object hiddenLifecycle = getLifecycle.invoke(activityPluginBinding);
      return getHiddenLifecycle(hiddenLifecycle);
    } catch (ClassNotFoundException
            | NoSuchMethodException
            | IllegalAccessException
            | InvocationTargetException e) {
      Log.w(
              TAG,
              "You are attempting to use Flutter plugins that are newer than your"
                      + " version of Flutter. Plugins may not work as expected.");
    }
    return null;
  }

The part that requires some more work is getting the integration test to launch a service and exercise this code path.

I'm starting with landing just an activity lifecycle getter to fix red CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecte: embedderUsers of the Embedder APIp: flutter_plugin_android_lifecycleThe flutter_plugin_android_lifecycle pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions