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.
This commit is contained in:
JosJuice 2020-11-06 22:35:37 +01:00
parent ee52f465b1
commit d982afd1ef
1 changed files with 18 additions and 3 deletions

View File

@ -12,6 +12,8 @@ import android.util.DisplayMetrics;
import android.view.Surface; import android.view.Surface;
import android.widget.Toast; import android.widget.Toast;
import androidx.fragment.app.FragmentManager;
import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.dialogs.AlertMessage; import org.dolphinemu.dolphinemu.dialogs.AlertMessage;
import org.dolphinemu.dolphinemu.utils.CompressCallback; import org.dolphinemu.dolphinemu.utils.CompressCallback;
@ -508,9 +510,22 @@ public final class NativeLibrary
{ {
sIsShowingAlertMessage = true; sIsShowingAlertMessage = true;
emulationActivity.runOnUiThread( emulationActivity.runOnUiThread(() ->
() -> AlertMessage.newInstance(caption, text, yesNo, isWarning) {
.show(emulationActivity.getSupportFragmentManager(), "AlertMessage")); 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. // Wait for the lock to notify that it is complete.
synchronized (sAlertMessageLock) synchronized (sAlertMessageLock)