How to resolve this orientation problem in Android?
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 orienta开发者_StackOverflowtion 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?
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)
.
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
精彩评论