Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Make executor an instance property #3633

Merged
merged 2 commits into from
Feb 25, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ build/
.project
.classpath
.settings

# Downloaded by the plugin tools.
google-java-format-1.3-all-deps.jar
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

private final android.content.SharedPreferences preferences;

private final ExecutorService executor;

/**
* Constructs a {@link MethodCallHandlerImpl} instance. Creates a {@link
* android.content.SharedPreferences} based on the {@code context}.
*/
MethodCallHandlerImpl(Context context) {
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
executor =
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}

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

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

executor.execute(
Expand Down