google-developer-training / basic-android-kotlin-compose-training-tip-calculator

Apache License 2.0
61 stars 97 forks source link

Screen orientation change doesn't preserve data | Calculate a custom tip: Android Basics in Compose #210

Open NumesSanguis opened 5 months ago

NumesSanguis commented 5 months ago

URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-compose-calculate-tip?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-calculate-tip#6

In which task and step of the codelab can this issue be found? Step 7

Describe the problem An explanation is lacking why, even with remember, on screen orientation changes result in all entered data being lost. Even when you entered a tip amount, tip percentage and toggled "round up tip", all this is gone when your phone switches to landscape.

This is very user-unfriendly. I might have typed out the bill amount and tip percentage. Now I want to show it to my friend, but I rotate my phone a bit too far by accident and trigger landscape. All information is now gone and I have to start from scratch.

An explanation of why remember in this situation is not enough and what is the best course of action if I want to make the app robust against losing the state on rotation would be very helpful.

Steps to reproduce?

  1. Deploy on actual Android (14) device with "Auto rotate" on.
  2. Have phone in Portrait mode
  3. Fill out text fields and toggle switch button
  4. Rotate phone so it switches to landscape
  5. Observe the text inputs and toggle button reset to default

Versions Android Studio version: API version of the emulator:

Additional information Include screenshots if they would be useful in clarifying the problem.