diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index e9d837de32..d97acb7adb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -917,8 +917,15 @@ public class FragmentCompose extends FragmentBase { } private void check() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) - checkInternet(); + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + checkInternet(); + } + }); } }; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 7d091e27dd..356b529510 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2734,8 +2734,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void check() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) - adapter.checkInternet(); + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + adapter.checkInternet(); + } + }); } }; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index cabd28070d..8f6ab4341f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -277,12 +277,21 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre }; private void showConnectionType() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { - ConnectionHelper.NetworkState networkState = ConnectionHelper.getNetworkState(getContext()); + FragmentActivity activity = getActivity(); + if (activity == null) + return; - tvConnectionType.setText(networkState.isUnmetered() ? R.string.title_legend_unmetered : R.string.title_legend_metered); - tvConnectionType.setVisibility(networkState.isConnected() ? View.VISIBLE : View.GONE); - tvConnectionRoaming.setVisibility(networkState.isRoaming() ? View.VISIBLE : View.GONE); - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { + ConnectionHelper.NetworkState networkState = ConnectionHelper.getNetworkState(getContext()); + + tvConnectionType.setText(networkState.isUnmetered() ? R.string.title_legend_unmetered : R.string.title_legend_metered); + tvConnectionType.setVisibility(networkState.isConnected() ? View.VISIBLE : View.GONE); + tvConnectionRoaming.setVisibility(networkState.isRoaming() ? View.VISIBLE : View.GONE); + } + } + }); } }