Make sure simple task delivers

This commit is contained in:
M66B 2019-07-30 17:02:21 +02:00
parent 0affd9e1f3
commit 3b51d9ce64
1 changed files with 14 additions and 15 deletions

View File

@ -129,21 +129,20 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
cleanup(context);
} else
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
// Deferred delivery
Log.i("Deferred delivery task " + name);
owner.getLifecycle().removeObserver(this);
deliver();
cleanup(context);
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
// No delivery
Log.i("Destroyed task " + name);
owner.getLifecycle().removeObserver(this);
cleanup(context);
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
public void onAny() {
Lifecycle.State state = owner.getLifecycle().getCurrentState();
if (state.equals(Lifecycle.State.DESTROYED)) {
Log.i("Destroyed task " + name);
owner.getLifecycle().removeObserver(this);
cleanup(context);
} else if (state.isAtLeast(Lifecycle.State.STARTED)) {
Log.i("Deferred delivery task " + name);
owner.getLifecycle().removeObserver(this);
deliver();
cleanup(context);
} else
Log.i("Task deferring " + state);
}
});
}