How to avoid restarting activity when orientation changes on Android

There are various ways to do it, but as given here, using

android:configChanges="keyboardHidden|orientation|screenSize"

allows you to listen for the config changes. You then respond to these changes by overriding onConfigurationChanged and calling setContentView.

This is the way I’ve been doing it, but I’d be interested to know other people’s thoughts.

Leave a Comment