you can make the application listen for events that will lead to changes related to restarting - such as the orientation and visibility of the keyboard - and process them as part of your work.
Start by adding android:configChangesnode to the node activity manifest
android:configChanges="keyboardHidden|orientation"
Then, as part of the Activity, override the onConfigurationChanged method and call setContentView to force the GUI layout to be redone in the new orientation.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.myLayout);
}
source
share