Skip to content

Make the example android app explicitly handle some device config change events to avoid getting the activity destroyed #18839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2025

Conversation

RabadanDotDev
Copy link
Contributor

Objective

Fixes #18316

Solution

Add android:configChanges="orientation|screenSize" to the AndroidManifest.xml as indicated in https://stackoverflow.com/a/3329486 to avoid the GameActivity from getting destroyed, making the app stuck/crash.

Testing

I checked the results in my phone and after adding the config change the issue went away. The change is relatively trivial, so there shouldn't be the need to make a lot more testing.

…tation to avoid getting the activity destroyed
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@RabadanDotDev RabadanDotDev changed the title fix(mobile): make the example android app explicitly handle device rotation to avoid getting the activity destroyed Make the example android app explicitly handle device rotation to avoid getting the activity destroyed Apr 14, 2025
Copy link
Contributor

@Henauxg Henauxg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also add the screenLayout flag ? This seems to be advised by the android documentation:

Note: If your application targets Android 3.2 (API level 13) or higher, also declare the 
"screenLayout" and "screenSize" configurations, because screen layout and screen size can 
change when a device switches between portrait and landscape orientations.

@RabadanDotDev
Copy link
Contributor Author

RabadanDotDev commented Apr 16, 2025

It looks like so. I'll add that now. I tried finding if it made a difference somewhere and seems that if you try using split-screen functionality without screenLayout it does trigger the destroy.

It is possible that more events of the list should be added just in case, or perhaps try to find a way for bevy to persist if the GameActivity is destroyed/recreated.

…out changes to avoid breaking on split screen
@RabadanDotDev
Copy link
Contributor Author

Looks like in Godot the solution was to basically add most of the list. I have the feeling that the best thing to do would be to add all of them to the list and pass the "onConfigurationChanged" event from android to the user in some way.

@Henauxg
Copy link
Contributor

Henauxg commented Apr 16, 2025

I'm fine with adding the configurations listed by Godot, most of them seem sensible enough (display and keyboards events). For the localization/layout, I've seen posts mentioning that layoutDirection could change while swapping to the phone photo mode, we wouldn't want the app to shutdown in this case.

Maybe the only one that I'm not sure about is navigation, as it says that it should not happen, but I guess there's no cost involved in adding it in ? BTW, is there a typo in the android documentation for this one ? Should it be A change to the navigation type instead of TA change ?

@RabadanDotDev
Copy link
Contributor Author

Ok perfect! I'll add that now.

I think navigation may happen if a user connects a game pad ("D-pad" as in the docs?) to the device while the app is running. Maybe it says that it doesn't normally happen, as in most apps people wouldn't use one, but for games it is kind of more possible.

And yeah, looks like there is a typo on there. Maybe an issue should be raised in their bug tracker.

@RabadanDotDev RabadanDotDev changed the title Make the example android app explicitly handle device rotation to avoid getting the activity destroyed Make the example android app explicitly handle some device config change events to avoid getting the activity destroyed Apr 16, 2025
@Henauxg Henauxg added C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples O-Android Specific to the Android mobile operating system S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Apr 23, 2025
@mockersf mockersf added this pull request to the merge queue Apr 26, 2025
Merged via the queue into bevyengine:main with commit c4408a8 Apr 26, 2025
40 checks passed
splo pushed a commit to splo/bevy that referenced this pull request Apr 29, 2025
…nge events to avoid getting the activity destroyed (bevyengine#18839)

# Objective

Fixes bevyengine#18316

## Solution

Add android:configChanges="orientation|screenSize" to the
AndroidManifest.xml as indicated in https://stackoverflow.com/a/3329486
to avoid the GameActivity from getting destroyed, making the app
stuck/crash.

## Testing

I checked the results in my phone and after adding the config change the
issue went away. The change is relatively trivial, so there shouldn't be
the need to make a lot more testing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples O-Android Specific to the Android mobile operating system S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Android) rotation mobile example black screen and then crash
3 participants