diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index cff3b5ced1..a7ce4c6cde 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -36,6 +36,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -212,7 +213,8 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 9801da5aaf..db48309f47 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -152,7 +152,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index a011dccc40..ae547d31c6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -39,6 +39,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -333,7 +334,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 09033d1607..1b1429727e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -43,6 +43,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -210,9 +211,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); - if ("last_cleanup".equals(key)) - setLastCleanup(prefs.getLong(key, -1)); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { + setOptions(); + if ("last_cleanup".equals(key)) + setLastCleanup(prefs.getLong(key, -1)); + } } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 35aeb5afbd..aab14c55c5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -45,6 +45,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; import static android.app.Activity.RESULT_OK; @@ -242,7 +243,8 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index d19766ed05..ff37df5a7c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -36,6 +36,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsSend extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -180,7 +181,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java index 0a5f6dab1f..7300cf964e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java @@ -42,6 +42,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.DialogFragment; +import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; import java.text.SimpleDateFormat; @@ -244,7 +245,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - setOptions(); + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); } @Override