diff --git a/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java b/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java index b708bf4..00c1717 100644 --- a/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java +++ b/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java @@ -1,25 +1,38 @@ package yy.inc.flutter_custom_dialog; +import androidx.annotation.NonNull; + +import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; -/** FlutterCustomDialogPlugin */ -public class FlutterCustomDialogPlugin implements MethodCallHandler { - /** Plugin registration. */ - public static void registerWith(Registrar registrar) { - final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_custom_dialog"); - channel.setMethodCallHandler(new FlutterCustomDialogPlugin()); +/** UntitledPlugin */ +public class FlutterCustomDialogPlugin implements FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private MethodChannel channel; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "untitled"); + channel.setMethodCallHandler(this); } @Override - public void onMethodCall(MethodCall call, Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { if (call.method.equals("getPlatformVersion")) { result.success("Android " + android.os.Build.VERSION.RELEASE); } else { result.notImplemented(); } } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index a7cbfba..78088c6 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,33 +1,42 @@ + package="yy.inc.flutter_custom_dialog_example"> - + android:label="flutter_custom_dialog_example" + android:icon="@mipmap/ic_launcher"> - + android:name=".MainActivity" + android:launchMode="singleTop" + android:theme="@style/LaunchTheme" + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" + android:hardwareAccelerated="true" + android:windowSoftInputMode="adjustResize"> + + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> + + + + diff --git a/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java b/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java index 5c5a420..7eefab5 100644 --- a/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java +++ b/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java @@ -1,13 +1,6 @@ package yy.inc.flutter_custom_dialog_example; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } }