Kill media tasks

This commit is contained in:
M66B
2025-02-05 18:14:58 +01:00
parent dd503c8197
commit 3327cde920
2 changed files with 15 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
private boolean log = true;
private boolean count = true;
private boolean keepawake = false;
private boolean kill = false;
private String id;
private String name;
@@ -104,6 +105,12 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
return this;
}
@NonNull
public SimpleTask<T> setKill(boolean kill) {
this.kill = kill;
return this;
}
@NonNull
public SimpleTask<T> setExecutor(ExecutorService executor) {
this.localExecutor = executor;
@@ -447,6 +454,13 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
}
protected void onDestroyed(Bundle args) {
if (this.kill && future != null)
try {
Log.i("Killing task=" + name);
future.cancel(true);
} catch (Throwable ex) {
Log.w(ex);
}
}
@Override