Reputation: 919
In my project I am taking one textview and one button and when I am clicking on button I am displaying some text in the textview which I am getting from an arraylist.
When I change the orientation to landscape I am using onSavedInstanceState(...) and onRestoreInstanceState(..) and getting the text displayed on textview and in landscape mode I am removing the text on textview and I am changing the orientation to portrait but I am getting the text on textview.
How can I resolve this?
Upvotes: 1
Views: 577
Reputation: 54705
TextView
saves its state by itself. If you don't want TextView
to save its state, add android:saveEnabled="false"
attribute or call TextView.setSaveEnabled(false)
.
Upvotes: 2
Reputation: 4102
On orientation changes, activity restarts. When an orientation change occurs Android calls a special method called onRetainNonConfigurationInstance. You can use this method to save an object, and afterwards you can get that object by using getLastNonConfigurationInstance method. You can see an example here
http://developer.android.com/resources/articles/faster-screen-orientation-change.html
Upvotes: 0