thibseisel / android-odeon

A simple but efficient music player on Android.
Apache License 2.0
68 stars 9 forks source link

Data loss on double screen rotation #28

Open davirec opened 2 years ago

davirec commented 2 years ago
  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)
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:

  1. https://developer.android.com/guide/components/activities/activity-lifecycle
  2. https://developer.android.com/topic/libraries/architecture/viewmodel
thibseisel commented 2 years ago

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 commented 2 years ago

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: