aragaer / jtt_android

android jtt app
MIT License
12 stars 6 forks source link

Data loss on double screen rotation #33

Open davirec opened 2 years ago

davirec commented 2 years ago

In the double screen rotation test to detect data loss, an application failure was identified:

JTTMainActivity: Two ideograms change, fragment disappears, the image rotates and the menu disappears.

Before and after double screen rotation
Before and after double screen rotation
Before and after double screen rotation
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
aragaer commented 2 years ago

JTTMainActivity doesn't store any data between app restarts, it delegates everything to the MainFragment instead. However the only data saved for fragment is "current page" and "current tick number". Menu state is not saved or restored (case 4). Image rotation (case 3) should not happen (since the tick number is saved) but it could happen if the tick happened between those two rotations. Case 1 is some kind of a visual issue -- the ideogram on the left is clearly incorrect. Case 2 should be handled by the SettingsFragment and that part is not implemented indeed.

davirec commented 2 years ago

Thanks.