From f050309ee92ea71abe0ef81cb91d94182a7c17da Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Fri, 20 Dec 2019 15:58:59 +0100 Subject: [PATCH] Android: fix IllegalStateException in onBackPressed() Rare exception, not catch-able, which appears when the activity gets in a broken state. java.lang.IllegalStateException: at android.app.FragmentManagerImpl.checkStateLoss (FragmentManagerImpl.java:1323) at android.app.FragmentManagerImpl.popBackStackImmediate (FragmentManagerImpl.java:493) at android.app.Activity.onBackPressed (Activity.java:2215) at org.libsdl.app.SDLActivity.onBackPressed (SDLActivity.java) at android.app.Activity.onKeyUp (Activity.java:2193) at android.view.KeyEvent.dispatch (KeyEvent.java:2685) at android.app.Activity.dispatchKeyEvent (Activity.java:2423) at org.libsdl.app.SDLActivity.dispatchKeyEvent (SDLActivity.java) --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 6a5c84acd..00e5f8f2b 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -453,7 +453,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } // Default system back button behavior. - super.onBackPressed(); + if (!isFinishing()) { + super.onBackPressed(); + } } // Called by JNI from SDL. @@ -466,7 +468,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh runOnUiThread(new Runnable() { @Override public void run() { - SDLActivity.this.superOnBackPressed(); + if (!SDLActivity.this.isFinishing()) { + SDLActivity.this.superOnBackPressed(); + } } }); }