Many recipes for this will have you handle orientation and keyboardHidden.
However, nowadays,
you need to also handle screenSize (and, in theory, smallestScreenSize),
if you have your android:targetSdkVersion set to 13 or higher.
Note that this will require your build target (e.g., compileSdkVersion in Android Studio) to be set to 13 or higher.