SDL
SDL copied to clipboard
Android status/system bars randomly won't hide when resuming the app
Hi!
There is an issue on Android where the system bars sometimes won't get hidden when focusing/resuming the app window. It happens randomly although much more frequently when the screen has to be rotated.
For example my application always runs in landscape mode, so if I have the home screen set to portrait mode and then switch between this and my application then the system bars won't get hidden around every third or fourth time. They will stay indefinitely and the only way to get rid of them is to go back to the home screen and then back to the app again.
Adding the following to SDLActivity::onSystemUiVisibilityChange() seems to completely resolve the issue but I'm pretty sure this is not a proper fix (and I think it only works on Android 11 and later):
getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.systemBars());
Based on the behavior I observe when the screen rotation takes place I suspect that this could be some kind of race condition where you are hiding the system bars before the screen rotation has been completed. However the issue can also occur when rotation does not take place, i.e. when the home screen is also set to landscape mode. But that is much less frequent and may happen only once every 10 or 15 tries.
@leonstyhre
I have disable the navigation bar feature in my side so I really don´t know what we should expect.
because it shows and then disappears and was more a source of trouble.
also my android setup is really out of date.
public void onSystemUiVisibilityChange(int visibility) seems to be user to hide the system bar.. can you check that "rehideSystemUi()" is called ?
( or maybe we should add a call:
mSingleton.sendCommand(COMMAND_CHANGE_WINDOW_STYLE, fullscreen ? 1 : 0);
in the onResume function )
Thanks for taking a look at this! I tried adding the following to SDLActivity::onResume() while also commenting out my overloaded onSystemUiVisibilityChange() method:
mSingleton.sendCommand(COMMAND_CHANGE_WINDOW_STYLE, mFullscreenModeActive ? 1 : 0);
While this improves things it's not perfect. The result is a bit glitchy as the system bars will be displayed when resuming the app, then disappear, then appear immediately again and disappear once more. So it happens twice for some reason. With the code mention in my first post it's much more seamless, the system bars are just faded out when resuming the app, which is the behavior you would expect.
I have also encountered this issue. It happens very consistently in portait mode for an app that uses landscape mode per default. When holding the phone in landscape mode the entire time, the bug does not seem to happen on my phone.
Not directly related to this bug, but I noticed that a wrong constant seems to be used as a system UI visibility flag:
https://github.com/libsdl-org/SDL/blob/4b3b5fb56c3aab094e431d3620d6cc36200430b8/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#L904-L910
https://github.com/libsdl-org/SDL/blob/4b3b5fb56c3aab094e431d3620d6cc36200430b8/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#L1738-L1745
The flag View.INVISIBLE is not supposed to be used with setSystemUiVisibility, though because its actual value is 4 it has no effect, as this is identical to value of the flag View.SYSTEM_UI_FLAG_FULLSCREEN.