The approach I took was to prevent the OS from restarting your activity after changing the layout configuration. To do this, add this line to the actions you want to prevent restarting in the manifest file:
<activity
android:configChanges="orientation|keyboard"
...
>
, , , , XML. onConfigurationChanged() Activity:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}