When I perform these sequences of events, the input text disappears on-screen rotation:
Go to the Main activity
Tap in Search (magnifying glass button icon)
Write a word
A screen similar to this will appear:
Before rotation:
Force the pause from the activity and then return to the activity (double rotation). Note that the input text disappears.
Note: the pause from activity can be performed in several ways. We suggest using a double rotation (starts in portrait, goes to landscape, and back to portrait) with this function previously enabled in the smartphone.
The expected behavior is the return to the previous state with the input text of the previous image.
However, the input text disappears.
After rotation:
Device:
Device: Moto G30 with OS: Android 11
Version: 2.7
Device language: English
Data loss
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 I perform these sequences of events, the input text disappears on-screen rotation:
Before rotation:
The expected behavior is the return to the previous state with the input text of the previous image.
However, the input text disappears.
After rotation:
Device:
Data loss
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).