Have you tried using: its work through
<activity name= ".YourActivity" android:configChanges="orientation|screenSize"/>
in Manifest file?
It does not work by default because , when you change the orientation onCreate
will be called again and it redraws your view.
If you write this parameter no need to handle in Activity , the framework will take care of rest of things.
It will retain the state of the screen or layout if orientation is changed.
NOTE If you are using a different layout for landscape mode , by adding these parameters the layout for landscape mode will not be called.
Other way and Another way
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…