user3121574
user3121574

Reputation:

Saving Android UI changes in onSaveInstanceState

I have read through all the other questions about this, but not one seems to answer my problem. I know how to save variables using onSaveInstanceState, but while reading through the docs, I came across this:

However, even if you do nothing and do not implement onSaveInstanceState(), some of the activity state is restored by the Activity class's default implementation of onSaveInstanceState(). Specifically, the default implementation calls the corresponding onSaveInstanceState() method for every View in the layout, which allows each view to provide information about itself that should be saved. Almost every widget in the Android framework implements this method as appropriate, such that any visible changes to the UI are automatically saved and restored when your activity is recreated. For example, the EditText widget saves any text entered by the user and the CheckBox widget saves whether it's checked or not. The only work required by you is to provide a unique ID (with the android:id attribute) for each widget you want to save its state. If a widget does not have an ID, then the system cannot save its state.

I have looked through my code. I have a unique ID for all my TextViews and I have called super.onSavedInstanceState in the method before saving any other variables. However, when I change orientations, all of my TextViews become blank. Any reason for this?

Upvotes: 1

Views: 119

Answers (1)

Rawa
Rawa

Reputation: 13906

Use the android:freezesText attribute on the TextView.

Upvotes: 0

Related Questions