diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java index fdc8391eba..4098c34585 100644 --- a/app/src/main/java/eu/faircode/email/SimpleTask.java +++ b/app/src/main/java/eu/faircode/email/SimpleTask.java @@ -45,6 +45,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; +import java.util.concurrent.RunnableFuture; +import java.util.concurrent.ThreadPoolExecutor; // This simple task is simple to use, but it is also simple to cause bugs that can easily lead to crashes // Make sure to not access any member in any outer scope from onExecute @@ -358,6 +360,11 @@ public abstract class SimpleTask implements LifecycleObserver { } void cancel(Context context) { + ExecutorService executor = getExecutor(context); + if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) { + boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future); + Log.i("Remove task=" + name + " removed=" + removed); + } if (future != null && future.cancel(false)) { Log.i("Cancelled task=" + name); cleanup(context);