Skip to content

Commit cb64042

Browse files
author
Emmanuel Garcia
authored
Make executor an instance property (flutter#3633)
1 parent f614980 commit cb64042

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ build/
4646
.project
4747
.classpath
4848
.settings
49+
50+
# Downloaded by the plugin tools.
51+
google-java-format-1.3-all-deps.jar

packages/shared_preferences/shared_preferences/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.2
2+
3+
* Don't create additional thread pools when method channel is called.
4+
15
## 2.0.1
26

37
* Removed deprecated [AsyncTask](https://developer.android.com/reference/android/os/AsyncTask) was deprecated in API level 30 ([#3481](https://github.com/flutter/plugins/pull/3481))

packages/shared_preferences/shared_preferences/android/src/main/java/io/flutter/plugins/sharedpreferences/MethodCallHandlerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
4343

4444
private final android.content.SharedPreferences preferences;
4545

46+
private final ExecutorService executor;
47+
4648
/**
4749
* Constructs a {@link MethodCallHandlerImpl} instance. Creates a {@link
4850
* android.content.SharedPreferences} based on the {@code context}.
4951
*/
5052
MethodCallHandlerImpl(Context context) {
5153
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
54+
executor =
55+
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
5256
}
5357

5458
@Override
@@ -123,8 +127,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
123127

124128
private void commitAsync(
125129
final SharedPreferences.Editor editor, final MethodChannel.Result result) {
126-
final ExecutorService executor =
127-
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
128130
final Handler handler = new Handler(Looper.getMainLooper());
129131

130132
executor.execute(

packages/shared_preferences/shared_preferences/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: shared_preferences
22
description: Flutter plugin for reading and writing simple key-value pairs.
33
Wraps NSUserDefaults on iOS and SharedPreferences on Android.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences
5-
version: 2.0.1
5+
version: 2.0.2
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)