From 05f62b4cae764f040632877ee42e781f1e476e45 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 15 Jan 2019 08:03:04 +0000 Subject: [PATCH] Prevent crash --- .../eu/faircode/email/FragmentMessages.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index f912646054..aca2fd3a54 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -449,13 +449,17 @@ public class FragmentMessages extends FragmentEx { public void onSelectionChanged() { // Workaround AndroidX bug FragmentActivity activity = getActivity(); - if (activity != null) { - ViewModelMessages modelMessages = ViewModelProviders.of(activity).get(ViewModelMessages.class); - if (selectionTracker.hasSelection()) - modelMessages.removeObservers(viewType, getViewLifecycleOwner()); - else - modelMessages.observe(viewType, getViewLifecycleOwner(), observer); - } + if (activity != null) + try { + ViewModelMessages modelMessages = ViewModelProviders.of(activity).get(ViewModelMessages.class); + if (selectionTracker.hasSelection()) + modelMessages.removeObservers(viewType, getViewLifecycleOwner()); + else + modelMessages.observe(viewType, getViewLifecycleOwner(), observer); + } catch (IllegalStateException ex) { + // getViewLifecycleOwner + Log.w(ex); + } if (selectionTracker.hasSelection()) { swipeRefresh.setEnabled(false);