diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-05-31 17:20:21 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-05-31 17:20:21 +0200 |
commit | ea6a008b39b0f669f66f3c8aec08b4deb3ece154 (patch) | |
tree | 9e009627ab1c2c4c86f4499e7cde6d094b4ec900 /src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java | |
parent | 1838023c88cee6aa68859ef24227cd81bc47b7f2 (diff) |
execute phone contact changes in singlethreadexecutor
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java b/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java index bfb4668d..55489ee3 100644 --- a/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java +++ b/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.utils; +import android.os.Looper; + import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.Executor; @@ -8,9 +10,24 @@ import java.util.concurrent.Executors; public class SerialSingleThreadExecutor implements Executor { final Executor executor = Executors.newSingleThreadExecutor(); - final Queue<Runnable> tasks = new ArrayDeque(); + protected final Queue<Runnable> tasks = new ArrayDeque(); Runnable active; + public SerialSingleThreadExecutor() { + this(false); + } + + public SerialSingleThreadExecutor(boolean prepareLooper) { + if (prepareLooper) { + execute(new Runnable() { + @Override + public void run() { + Looper.prepare(); + } + }); + } + } + public synchronized void execute(final Runnable r) { tasks.offer(new Runnable() { public void run() { |