Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider registering plugins in FlutterApplication #9215

Closed
mit-mit opened this Issue Apr 5, 2017 · 11 comments

Comments

Projects
5 participants
@mit-mit
Copy link
Member

mit-mit commented Apr 5, 2017

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.

@mit-mit mit-mit added the p: tooling label Apr 5, 2017

@mit-mit

This comment has been minimized.

Copy link
Member Author

mit-mit commented Apr 5, 2017

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

@mit-mit

This comment has been minimized.

Copy link
Member Author

mit-mit commented Apr 7, 2017

Tagging M2 as this impacts API stability

@mit-mit mit-mit added this to API Stability in M2 Apr 7, 2017

@eseidelGoogle eseidelGoogle moved this from API Stability to In Progress in M2 Apr 18, 2017

@eseidelGoogle eseidelGoogle moved this from In Progress to Docs/Site in M2 Apr 25, 2017

@eseidelGoogle eseidelGoogle moved this from Docs/Site to API Stability in M2 Apr 25, 2017

@collinjackson

This comment has been minimized.

Copy link
Contributor

collinjackson commented Apr 28, 2017

@goderbauer

This comment has been minimized.

Copy link
Member

goderbauer commented May 5, 2017

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

@collinjackson

This comment has been minimized.

Copy link
Contributor

collinjackson commented May 5, 2017

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.

@mravn-google

This comment has been minimized.

Copy link
Contributor

mravn-google commented May 5, 2017

#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:

@mravn-google

This comment has been minimized.

Copy link
Contributor

mravn-google commented May 5, 2017

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.

@mravn-google

This comment has been minimized.

Copy link
Contributor

mravn-google commented May 5, 2017

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) { ... }
}
@collinjackson

This comment has been minimized.

Copy link
Contributor

collinjackson commented May 5, 2017

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.

@goderbauer

This comment has been minimized.

Copy link
Member

goderbauer commented May 5, 2017

Nice!

@mravn-google

This comment has been minimized.

Copy link
Contributor

mravn-google commented May 9, 2017

Fixed by #9715 and friends.

@mit-mit mit-mit moved this from API Stability to Done in M2 May 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.