TextView's text disappearing when device rotated
What @jeet recommended didn't work for me. I had to add "screenSize". This is the line you should add in your manifest.xml in the <activity>
node of your activity:
android:configChanges="keyboardHidden|orientation|screenSize"
Thus, the complete node may look like this:
<activity
android:name=".YourActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar">
Please check on orientation change, on create method is called, which requires all the views to be created again, so you need to use one of the following methods:
- use onSavedInstance method and save the states of components/views to bundle.
Just use following flag true in your manifest file in activity tag android:configChanges="keyboardHidden|orientation". like below:
<activity android:name=".SampleActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"> ... </activity>
The reason for this is due to Android basically destroying the activity and creating it again every time you rotate the device. This is mainly to allow for different layouts based on portrait/landscape mode.
The best way to handle this is to store whatever data you need to keep within the Activity Bundle, by responding to the onSavedInstance event (called just before Android destroys the activity), and then reapplying those in the standard onCreate event.
Although you can add "orientation" to the configChanges property, keep in mind that you're basically telling Android that you're going to be handling everything relating to orientation change yourself - including changing layout, etc.