From 03beb691e87e257e03913c420fe17e2a23262c68 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Jun 2022 22:20:02 +0200 Subject: [PATCH] Fixed fragment back --- app/src/main/java/eu/faircode/email/FragmentBase.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 092ba7c521..02c7de0fb0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -422,17 +422,17 @@ public class FragmentBase extends Fragment { } protected void setBackPressedCallback(OnBackPressedCallback backPressedCallback) { - backPressedCallback.setEnabled(false); FragmentActivity activity = getActivity(); if (activity == null) return; - activity.getOnBackPressedDispatcher().addCallback(backPressedCallback); + backPressedCallback.setEnabled(true); getViewLifecycleOwner().getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_ANY) public void onAny() { Lifecycle.State state = getViewLifecycleOwner().getLifecycle().getCurrentState(); - backPressedCallback.setEnabled(state.isAtLeast(Lifecycle.State.STARTED)); - if (state.isAtLeast(Lifecycle.State.DESTROYED)) + if (state.isAtLeast(Lifecycle.State.STARTED)) + activity.getOnBackPressedDispatcher().addCallback(backPressedCallback); + else backPressedCallback.remove(); } });