Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip
  • Loading branch information
hoc081098 committed Feb 26, 2021
commit 6006b2a76a5400bf7defb9455a78712ccdd95f34
4 changes: 4 additions & 0 deletions packages/shared_preferences/shared_preferences/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.3

* Don't create additional handler when method channel is called.

## 2.0.2

* Don't create additional thread pools when method channel is called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
private final android.content.SharedPreferences preferences;

private final ExecutorService executor;
private final Handler handler;

/**
* Constructs a {@link MethodCallHandlerImpl} instance. Creates a {@link
Expand All @@ -53,6 +54,7 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
executor =
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
handler = new Handler(Looper.getMainLooper());
}

@Override
Expand Down Expand Up @@ -125,10 +127,13 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
}
}

public void teardown() {
handler.removeCallbacksAndMessages(null);
executor.shutdown();
}

private void commitAsync(
final SharedPreferences.Editor editor, final MethodChannel.Result result) {
final Handler handler = new Handler(Looper.getMainLooper());

executor.execute(
new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class SharedPreferencesPlugin implements FlutterPlugin {
private static final String CHANNEL_NAME = "plugins.flutter.io/shared_preferences";
private MethodChannel channel;
private MethodCallHandlerImpl handler;

@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
Expand All @@ -32,11 +33,13 @@ public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding binding) {

private void setupChannel(BinaryMessenger messenger, Context context) {
channel = new MethodChannel(messenger, CHANNEL_NAME);
MethodCallHandlerImpl handler = new MethodCallHandlerImpl(context);
handler = new MethodCallHandlerImpl(context);
channel.setMethodCallHandler(handler);
}

private void teardownChannel() {
handler.teardown();
handler = null;
channel.setMethodCallHandler(null);
channel = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences
description: Flutter plugin for reading and writing simple key-value pairs.
Wraps NSUserDefaults on iOS and SharedPreferences on Android.
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences
version: 2.0.2
version: 2.0.3

flutter:
plugin:
Expand Down