From d982afd1eff1b7ce8c8c8c969f49d12b3b763098 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 6 Nov 2020 22:35:37 +0100 Subject: [PATCH] Android: Fix alert messages when EmulationActivity is being destroyed The previous commit made this easy to reproduce when launching an invalid disc image with the phone rotated incorrectly. --- .../dolphinemu/dolphinemu/NativeLibrary.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 0c35a35da0..486e5bab7d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -12,6 +12,8 @@ import android.util.DisplayMetrics; import android.view.Surface; import android.widget.Toast; +import androidx.fragment.app.FragmentManager; + import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.dialogs.AlertMessage; import org.dolphinemu.dolphinemu.utils.CompressCallback; @@ -508,9 +510,22 @@ public final class NativeLibrary { sIsShowingAlertMessage = true; - emulationActivity.runOnUiThread( - () -> AlertMessage.newInstance(caption, text, yesNo, isWarning) - .show(emulationActivity.getSupportFragmentManager(), "AlertMessage")); + emulationActivity.runOnUiThread(() -> + { + FragmentManager fragmentManager = emulationActivity.getSupportFragmentManager(); + if (fragmentManager.isStateSaved()) + { + // The activity is being destroyed, so we can't use it to display an AlertMessage. + // Fall back to a toast. + Toast.makeText(emulationActivity, text, Toast.LENGTH_LONG).show(); + NotifyAlertMessageLock(); + } + else + { + AlertMessage.newInstance(caption, text, yesNo, isWarning) + .show(fragmentManager, "AlertMessage"); + } + }); // Wait for the lock to notify that it is complete. synchronized (sAlertMessageLock)