Skip to content

Commit

Permalink
Android: fix IllegalStateException in onBackPressed()
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
1bsyl committed Dec 20, 2019
1 parent 9996d1b commit f050309
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -453,7 +453,9 @@ public void onBackPressed() {
}

// Default system back button behavior.
super.onBackPressed();
if (!isFinishing()) {
super.onBackPressed();
}
}

// Called by JNI from SDL.
Expand All @@ -466,7 +468,9 @@ public void pressBackButton() {
runOnUiThread(new Runnable() {
@Override
public void run() {
SDLActivity.this.superOnBackPressed();
if (!SDLActivity.this.isFinishing()) {
SDLActivity.this.superOnBackPressed();
}
}
});
}
Expand Down

0 comments on commit f050309

Please sign in to comment.