Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 ?