From 6f7a310438826590893c735ad048d6bc1353911f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 20 Jan 2019 17:41:47 +0000 Subject: [PATCH] Prevent crash --- .../main/java/eu/faircode/email/FragmentOptions.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 8e3ec13e14..93ff9d44b6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -48,6 +48,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; import androidx.fragment.app.FragmentActivity; +import androidx.lifecycle.Lifecycle; import static android.app.Activity.RESULT_OK; @@ -454,11 +455,13 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O activity.runOnUiThread(new Runnable() { @Override public void run() { - Boolean metered = Helper.isMetered(getContext(), false); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + Boolean metered = Helper.isMetered(getContext(), false); - tvConnectionType.setVisibility(metered == null ? View.GONE : View.VISIBLE); - if (metered != null) - tvConnectionType.setText(metered ? R.string.title_legend_metered : R.string.title_legend_unmetered); + tvConnectionType.setVisibility(metered == null ? View.GONE : View.VISIBLE); + if (metered != null) + tvConnectionType.setText(metered ? R.string.title_legend_metered : R.string.title_legend_unmetered); + } } }); }