Skip to content

Consider registering plugins in FlutterApplication #9215

Closed

Description

@mit-mit

From @collinjackson: consider autoregistering in the FlutterApplication and adding an activity lifecycle callback so plugins get added in onCreate automatically without having extra code in the client activity.

Activity

  1. mit-mit commented on Apr 5, 2017

    @mit-mit
    MemberAuthor

    @mravn-google can you look into this a bit?

  2. mit-mit commented on Apr 7, 2017

    @mit-mit
    MemberAuthor

    Tagging M2 as this impacts API stability

  3. collinjackson commented on Apr 28, 2017

    @collinjackson
    Contributor
  4. added and removed
    p: toolingAffects the flutter_plugin_tools package
    on May 2, 2017
  5. goderbauer commented on May 5, 2017

    @goderbauer
    Member

    It would also be nice if plugins can be informed about the "onNewIntent" event. That would for example make the setup for the firebase_messaging plugin a lot simpler, as we could then drop step 2ii from our instructions: https://github.com/flutter/firebase_messaging

  6. collinjackson commented on May 5, 2017

    @collinjackson
    Contributor

    I agree that FlutterActivity should allow plugins to register for onNewIntent and various other Activity methods, like onUserLeaveHint(). It might be better to fix #3671 first, since it could have impact on the API design if plugins can exist outside of a FlutterActivity.

  7. mravn-google commented on May 5, 2017

    @mravn-google
    Contributor

    #9715 and friends contains a basic approach that we can extend until it handles all the Activity methods we want. It does not tie plugins to a FlutterActivity, though still to an Activity. Comments/suggestions on the PRs are most welcome.

    Android:

    iOS:

  8. mravn-google commented on May 5, 2017

    @mravn-google
    Contributor

    BTW: I don't immediately see a simple way to avoid plugin registration code in the client's Activity as long as we have the auto-generated PluginRegistry.java (soon to become GeneratedPluginRegistrant.java).

    Calling the auto-generated code from flutter/engine framework code seems to require reflection which (in my view) isn't simple, even if it's just a few lines of Java.

  9. mravn-google commented on May 5, 2017

    @mravn-google
    Contributor

    onUserLeaveHint and onNewIntent are now both included:

    public final class MyPlugin implements
      MethodCallHandler, NewIntentListener, UserLeaveHintListener {
    
      public static void registerWith(Registrar registrar) {
        final MethodChannel channel = new MethodChannel(registrar.messenger(), "my");
        final MyPlugin instance = new MyPlugin(registrar.activity(), channel);
        registrar
          .addNewIntentListener(instance)
          .addUserLeaveHintListener(instance);
        channel.addMethodCallHandler(instance);
      }
      
      private MyPlugin(Activity activity, MethodChannel channel) { ... };
    
      @Override
      public void handleMethodCall(MethodCall call, Result result) { ... }
      @Override
      public void onUserLeaveHint() { ... }
      @Override
      public void onNewIntent(Intent intent) { ... }
    }
  10. collinjackson commented on May 5, 2017

    @collinjackson
    Contributor

    Thanks! I don't have any particular attachment to onUserLeaveHint, it's just an example, but hopefully we'll get all the useful ones over time.

  11. goderbauer commented on May 5, 2017

    @goderbauer
    Member

    Nice!

  12. mravn-google commented on May 9, 2017

    @mravn-google
    Contributor

    Fixed by #9715 and friends.

  13. github-actions commented on Sep 5, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: API breakBackwards-incompatible API changes

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions