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

Data loss on double screen rotation #28

Open
davirec opened this issue Mar 24, 2022 · 2 comments
Open

Data loss on double screen rotation #28

davirec opened this issue Mar 24, 2022 · 2 comments

Comments

@davirec
Copy link

davirec commented Mar 24, 2022

  • When executing this sequence of actions, there is a loss of data in the activity HomeActivity:
  1. KeyEvent(name=BACK)
  2. IntentEvent(intent='am start fr.nihilus.music/fr.nihilus.music.HomeActivity')
  3. TouchEvent [[540,152],[720,236]]
  4. TouchEvent [[360,152],[540,236]]
  5. TouchEvent [[565,61],[649,145]]
  6. TouchEvent [[628,71],[712,155]]
  7. SetTextEvent [[134,64],[628,162]]
  8. ScrollEvent(direction=FULL_LEFT)
  9. ScrollEvent(direction=UP) [[0,236],[720,1558]]
  10. Cap01: capture screen properties before rotation
  11. DoubleRotationEvent
  12. Cap02: capture screen properties after rotation
  13. Cap01 != Cap02 (focus variable changes state)
  • HomeActivity: the pop-up menu disappears
Before and after double screen rotation

A data loss problem occurs when data is accidentally deleted or state variables are accidentally assigned with default or initial values. This issue is related to the activity's lifecycle (1). When a screen rotation occurs, the activity is destroyed and resumed. Data loss will happen if the developer does not save the variables before the destruction and restore them after creation. To avoid this, the developers have to implement both the logic necessary to save the activity state in the onSaveInstanceState() callback method and the logic to resume its state in the onRestoreInstanceState() callback method.
Another way to avoid data loss problems is to use the view model, designed to store and manage UI-related data in a lifecycle-conscious way (2).

Note:

  • Double screen rotation: It is executed twice to reach a state that should be exactly the same as the screen before if no data loss occurred.
  • A data loss problem occurs when data is accidentally deleted or state variables are accidentally assigned with default or initial values.
  1. https://developer.android.com/guide/components/activities/activity-lifecycle
  2. https://developer.android.com/topic/libraries/architecture/viewmodel
@thibseisel
Copy link
Owner

Hi @davirec,

Thanks for this detailed bug report. I am able to reproduce the issue. However, coordinates in your reproduction scenario are only valid when testing on the same device as yours ; please specify with which Android device and version you reproduced the bug.

I understand the concerns behind data loss, but I have to admit that I don't understand how impacting this is in this particular case. Does that loss of focus is frequently hindering your user experience? Feel free to tell me more 🙂

@davirec
Copy link
Author

davirec commented Jul 2, 2022

Hi thibseisel! Sorry, did not mean to ignore you, somehow notifications went past me.

I'm working with apps hosted on F-droid to check for data loss after double screen rotation for a software engineering experiment. Among the activities of this research is to report the failures found to the developers. We are working to understand how the data loss problem manifests itself in applications to develop automated solutions, following the android documentation guidelines.

Device:

  • Device: Moto G30 with OS: Android 11
  • Version: 1.3.0
  • Device language: English

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants