adolfintel / OpenPods

The Free and Open Source app for monitoring your AirPods on Android
https://fdossena.com/?p=openPods/index.frag
GNU General Public License v3.0
969 stars 164 forks source link

Data loss while using the app (differences between view properties) #146

Open davirec opened 2 years ago

davirec commented 2 years ago

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).

When executing this sequence of actions, there is a loss of data in the activity MainActivity:

  1. ScrollEvent(direction=UP) [[21,526],[701,1560]]
  2. TouchEvent [[283,421],[437,505]]
  3. IntentEvent(intent='am start com.dosse.airpods/com.dosse.airpods.ui.MainActivity')
  4. TouchEvent [[35,722],[220,757]]
  5. IntentEvent(intent='am start com.dosse.airpods/com.dosse.airpods.ui.MainActivity')
  6. Cap01: capture screen properties before rotation
  7. DoubleRotationEvent
  8. Cap02: capture screen properties after rotation
  9. Cap01 != Cap02 (differences between view properties)

Device:

Note:

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