From 2944c65b1832206b37a11733ba0ef2039c6ca611 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 11 Jan 2020 08:39:38 +0100 Subject: [PATCH] Fixed selecting key on some Android versions --- app/src/main/java/eu/faircode/email/Helper.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index da5e96773b..1cc2694fe7 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -82,7 +82,9 @@ import androidx.core.content.FileProvider; import androidx.core.graphics.ColorUtils; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.RecyclerView; @@ -937,11 +939,23 @@ public class Helper { handler.post(new Runnable() { @Override public void run() { - if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (alias == null) intf.onNothingSelected(); else intf.onSelected(alias); + } else { + owner.getLifecycle().addObserver(new LifecycleObserver() { + @OnLifecycleEvent(Lifecycle.Event.ON_START) + public void onStart() { + owner.getLifecycle().removeObserver(this); + if (alias == null) + intf.onNothingSelected(); + else + intf.onSelected(alias); + } + }); + } } }); }