Skip to content
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

Android app restarts and lose place when folding/unfolding phone #6693

Open
odbol opened this issue Nov 24, 2024 · 12 comments
Open

Android app restarts and lose place when folding/unfolding phone #6693

odbol opened this issue Nov 24, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@odbol
Copy link

odbol commented Nov 24, 2024

Steps to Reproduce

  1. Click a post to view comments
  2. Unfold phone, or otherwise trigger onConfigurationChange. (e.g. if you don't have a foldable: trigger accessibility > color inversion, or split screen the app)
  3. The app restarts

Observed:
I'm back at the start of my feed, no way to get back to the post I was on.

Expected:
The app restores the screen I was last on: in this case, viewing a specific post.

Ideally it would also restore my scroll position in the feed, but maybe that's a separate fix.

Attachments

No response

What platform(s) does this occur on?

Android

Device Info

Pixel fold 2, Android 15

What version of the app are you using?

Build version: 1.94.0.402; Bundle info: c59dc0d (prod); Bundle date: 24112017; Platform: android; Platform version: 35

Additional Information

Two ways to solve this

  1. implement saving the app state to a bundle and restoring from that bundle in onCreate. (This technique also helps with other situations, e.g. if the app is killed due to low memory)

  2. Or, handle screen resize configuration changes by adding them to your activity tag in the manifest, and then resizing in onConfigurationChange. (Harder, doesn't solve situations where app is killed)

@odbol odbol added the bug Something isn't working label Nov 24, 2024
@joakimcarlgren
Copy link

Other configuration changes that will have similar impact

  1. changing text size
  2. changing dark/light theme
  3. changing anything locale related

@ngencokamin
Copy link

ngencokamin commented Nov 24, 2024

Reproduced this issue w a screen recording:

Platform

Android

Device Info

Samsung Galaxy Fold 4. Currently running Android 14 (OneUI Version 6.1.1)

App Version

Build version: 1.94.0.402; Bundle info: 3c30bb1 (prod); Bundle date: 24111623; Platform: android; Platform version: 34

Screen Recording

XRecorder_24112024_112614.mp4

Just like OP, I'm not sure if scrolling back to current place in timeline is doable/how hard it is. But would be nice if the app didn't restart fully on state change.

@gaearon
Copy link
Collaborator

gaearon commented Nov 24, 2024

Would be nice to figure out what causes the restart! I don't think our code is doing this intentionally

@ngencokamin
Copy link

Would be nice to figure out what causes the restart! I don't think our code is doing this intentionally

Let me know if there's anything I can do to help debug :) I'm an sdet with too much time on their hands, so I'd love to be useful haha

@gaearon
Copy link
Collaborator

gaearon commented Nov 24, 2024

@ngencokamin

I'm guessing there isn't much test-oriented follow up here, if you'd like to dig into the cause I'd assume it's something related to the Android manifest settings and whatever Expo is using as a default. Since the screen size changes, it might be possible that the app is not currently resilient to that anyway, in which case we'd have to fix that first before making this seamless. If you can dig into the root cause (e.g. the Android manifest setting that tweaks this behavior), that would be helpful, but you'd probably have to run the build locally to do that. Alternatively, if you'd like to help with the project in general, looking over other issues and trying to record repro cases is very useful. Thank you.

@ngencokamin
Copy link

@ngencokamin

I'm guessing there isn't much test-oriented follow up here, if you'd like to dig into the cause I'd assume it's something related to the Android manifest settings and whatever Expo is using as a default. Since the screen size changes, it might be possible that the app is not currently resilient to that anyway, in which case we'd have to fix that first before making this seamless. If you can dig into the root cause (e.g. the Android manifest setting that tweaks this behavior), that would be helpful, but you'd probably have to run the build locally to do that. Alternatively, if you'd like to help with the project in general, looking over other issues and trying to record repro cases is very useful. Thank you.

Sounds good, thank you! I've definitely been looking through some issues and recording repros already 😊

@odbol
Copy link
Author

odbol commented Nov 24, 2024

I think this could help: https://reactnavigation.org/docs/state-persistence/

Something to do with saving state in Android: https://developer.android.com/topic/libraries/architecture/saving-states

@ngencokamin
Copy link

I think this could help: https://reactnavigation.org/docs/state-persistence/

Something to do with saving state in Android: https://developer.android.com/topic/libraries/architecture/saving-states

I'll take a look in a bit!

@joakimcarlgren
Copy link

Would be nice to figure out what causes the restart! I don't think our code is doing this intentionally

A resizing of the screen triggers a configuration change. A configuration change restarts your Android Activity or fragment. If you don't restore state properly in that context then you can end up with state loss.

@joakimcarlgren
Copy link

You can test configuration changes by enabling orientation change on debug builds, and then use that across the app to see how well you recover per screen.

(If it's indeed configuration change related)

@gaearon
Copy link
Collaborator

gaearon commented Nov 25, 2024

Does configuration change always restart an activity?

@joakimcarlgren
Copy link

joakimcarlgren commented Nov 25, 2024

Does configuration change always restart an activity?

You can edit your manifest and tell it that you're handling some changes yourself, but I'm not sure it allows all config changes.

https://developer.android.com/guide/topics/resources/runtime-changes

But activity recreation can happen in other cases as well, so the key is to always make sure you restore state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants