|
10 | 10 |
|
11 | 11 | /** ObjectboxFlutterLibsPlugin */
|
12 | 12 | public class ObjectboxFlutterLibsPlugin implements FlutterPlugin, MethodCallHandler {
|
13 |
| - /// The MethodChannel that will the communication between Flutter and native Android |
14 |
| - /// |
15 |
| - /// This local reference serves to register the plugin with the Flutter Engine and unregister it |
16 |
| - /// when the Flutter Engine is detached from the Activity |
17 |
| - private MethodChannel channel; |
18 |
| - |
19 |
| - @Override |
20 |
| - public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { |
21 |
| - channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "objectbox_flutter_libs"); |
22 |
| - channel.setMethodCallHandler(this); |
23 |
| - } |
24 |
| - |
25 |
| - @Override |
26 |
| - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { |
27 |
| - if (call.method.equals("getPlatformVersion")) { |
28 |
| - result.success("Android " + android.os.Build.VERSION.RELEASE); |
29 |
| - } else { |
30 |
| - result.notImplemented(); |
| 13 | + /// The MethodChannel that will the communication between Flutter and native Android |
| 14 | + /// |
| 15 | + /// This local reference serves to register the plugin with the Flutter Engine and unregister it |
| 16 | + /// when the Flutter Engine is detached from the Activity |
| 17 | + private MethodChannel channel; |
| 18 | + |
| 19 | + @Override |
| 20 | + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { |
| 21 | + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "objectbox_flutter_libs"); |
| 22 | + channel.setMethodCallHandler(this); |
| 23 | + loadLibrary(); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { |
| 28 | + if (call.method.equals("getPlatformVersion")) { |
| 29 | + result.success("Android " + android.os.Build.VERSION.RELEASE); |
| 30 | + } else { |
| 31 | + result.notImplemented(); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { |
| 37 | + channel.setMethodCallHandler(null); |
31 | 38 | }
|
32 |
| - } |
33 | 39 |
|
34 |
| - @Override |
35 |
| - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { |
36 |
| - channel.setMethodCallHandler(null); |
37 |
| - } |
| 40 | + private static boolean isLibraryLoaded = false; |
| 41 | + |
| 42 | + private static void loadLibrary() { |
| 43 | + if (isLibraryLoaded) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + // Loads `libobjectbox-jni.so`. |
| 48 | + System.loadLibrary("objectbox-jni"); |
| 49 | + isLibraryLoaded = true; |
| 50 | + } |
38 | 51 | }
|
0 commit comments