From 3b51d9ce64688f107d4e66eb931fb2b7a8e1f400 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 30 Jul 2019 17:02:21 +0200 Subject: [PATCH] Make sure simple task delivers --- .../java/eu/faircode/email/SimpleTask.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java index 4807bae18f..2c4bb255a3 100644 --- a/app/src/main/java/eu/faircode/email/SimpleTask.java +++ b/app/src/main/java/eu/faircode/email/SimpleTask.java @@ -129,21 +129,20 @@ public abstract class SimpleTask 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); } }); }