mirror of https://github.com/M66B/FairEmail.git
You're being watched
This commit is contained in:
parent
12e577fc9a
commit
d303a859a8
|
@ -144,6 +144,14 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
}
|
||||
|
||||
LifecycleObserver watcher = new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
cancel(context);
|
||||
owner.getLifecycle().removeObserver(this);
|
||||
}
|
||||
};
|
||||
|
||||
future = getExecutor(context).submit(new Runnable() {
|
||||
private Object data;
|
||||
private long elapsed;
|
||||
|
@ -181,7 +189,10 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||
// No delivery
|
||||
cleanup(context);
|
||||
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
} else {
|
||||
owner.getLifecycle().removeObserver(watcher);
|
||||
|
||||
if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
// Inline delivery
|
||||
Log.i("Deliver task " + name + " state=" + state + " elapse=" + elapsed + " ms");
|
||||
deliver();
|
||||
|
@ -207,6 +218,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deliver() {
|
||||
try {
|
||||
|
@ -249,6 +261,8 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
});
|
||||
|
||||
owner.getLifecycle().addObserver(watcher);
|
||||
|
||||
updateTaskCount(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue