Single shot tasks

This commit is contained in:
M66B 2022-08-13 09:08:13 +02:00
parent aef7175dd0
commit b506a2b579
2 changed files with 11 additions and 1 deletions

View File

@ -6138,7 +6138,7 @@ public class FragmentMessages extends FragmentBase
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.setExecutor(executor).execute(this, args, "quickactions");
}.setExecutor(executor).setId("messages:" + FragmentMessages.this.hashCode()).execute(this, args, "quickactions");
} else {
fabMore.hide();
tvSelectedCount.setVisibility(View.GONE);

View File

@ -54,6 +54,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
private boolean count = true;
private boolean keepawake = false;
private String id;
private String name;
private long started;
private boolean destroyed;
@ -74,6 +75,11 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
public SimpleTask<T> setId(String id) {
this.id = id;
return this;
}
public SimpleTask<T> setLog(boolean log) {
this.log = log;
if (!log)
@ -143,6 +149,10 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
// prevent garbage collection
synchronized (tasks) {
if (id != null)
for (SimpleTask task : tasks)
if (id.equals(task.id))
task.cancel(context);
tasks.add(this);
}