Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Activity Lifecycle Introducing SharedPreferences Introduction to SharedPreferences

change of state during orientation

why editText retained it's value during screen rotation?Which is contradictory to what we saw in fun facts project.

3 Answers

Actually on the FunFacts we used TextViews instead of EditTexts.

TextViews values won't be saved automatically different than EditText because on EditText there is a flag called "freezeText' that is set to "true" by default, but you can make the TexView do the same by setting the "freezeText" flag to true via xml android:freezesText="true" or TextView#setFreezesText(true) on the widget. Otherwise you will have to make it manually as it was done on the FunFacts app.

I create a log statement to see what's the value of freezeText attribute in EditText by default and I get a false Log.d("TAG", mEditText.getFreezesText() + "");

Joe Brown
Joe Brown
21,465 Points

If I remember right, that is just a sort of courtesy the system provides for you since it is such a common thing. It is most likely stored in the savedInstanceState Bundle and restored for you then after rotation/recreation.

I have the same question too. Don't we name all our view ids "uniquely" in the Fun Facts project ?