From 548450a56ab4cd3a39fce609a3bf5baea85ca9bd Mon Sep 17 00:00:00 2001 From: Kurt Aaholst Date: Thu, 20 Jun 2024 08:28:29 +0200 Subject: [PATCH] Resolve IllegalStateException, Fragment.requireContext Even if isAdded is called just before showConnectingDialog, it may be disconnected once we get in the main thread after getting the preferences. --- .../main/java/uk/org/ngo/squeezer/NowPlayingFragment.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java index 003a23830..72f145111 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java @@ -223,6 +223,11 @@ public void onReceive(Context context, Intent intent) { private void showConnectingDialog() { if (connectingDialog == null || !connectingDialog.isShowing()) { Squeezer.getPreferences(preferences -> { + // We may no longer be attached to the parent activity. If so, do nothing. + if (isAdded()) { + return; + } + Preferences.ServerAddress serverAddress = preferences.getServerAddress(); final View view = LayoutInflater.from(mActivity).inflate(R.layout.connecting, null);