Android: What happens when you rotate the device… 180 degrees?
It is not the same as 90 degrees.
Rotation is something any Android developer that’s not new knows about. It’s one of the first things you learn and is a common interview question. If you want a nice app with an adaptable UI for both portrait and landscape, then when the user rotates the device (90 degrees), you need to know the details of what happens to the activity and how to handle that or stop that.
This isn’t a tutorial for handling 90 degree rotations, but still, to give some context, Android destroys and recreates the activity whenever an unhandled configuration change occurs. And everything is considered unhandled by default unless you set flags to android:configChanges within your <activity> in the AndroidManifest.xml. You must set the orientation and screenSize flags to prevent activity restart on 90 degree rotations, then instead of activity restart your activity will just receive a callback to onConfigurationChanged.
In my experience, whenever rotation is discussed whether it’s a 90 degree or 180 degree rotation is never mentioned or specified, and it is always unknowingly assumed that the rotation is 90 degrees. For example this ViewModel overview from Google talks about rotation twice and is incorrect both times if the rotation is 180 degrees. So I find this an interesting and unknown piece of Android to dig into.
The difference
A 90 degree rotation will cause an orientation change. The device is being changed between portrait and landscape. Non-reverse vs reverse is not relevant.
A 180 degree rotation will not cause an orientation change. The device is only being changed either between portrait and reverse-portrait or landscape and reverse-landscape. Either way, Android doesn’t consider this an orientation or configuration change. This won’t trigger activity restart and won’t trigger the activity’s onConfigurationChanged().
This seems reasonable. After all, a 180 degree rotation does not change the aspect ratio of the display. So the same layout should work, right? Well, usually it should, but if your app renders content in display cutout areas, then you might need to watch out.
FYI: Portrait vs Reverse-Portrait
With a typical device, portrait is when you hold the device such that the camera is at the top. Reverse-portrait is when you hold the device such that the camera is at the bottom. On the majority of phones reverse-portrait is disabled, so even if an app allows it the system won’t rotate the screen when you put the device upside down. I’ve seen some phones that allow you to change this in settings and some that don’t. So besides phone-enthusiasts, for the most part I believe reverse-portrait is an experience limited to tablet users since tablets are more likely to have reverse-portrait enabled.
FYI: Landscape vs Reverse-Landscape
Landscape is when you hold the device long-ways such that with a typical device the camera is then either on the left or on the right. And any and every device I’ve seen allows both landscape and reverse landscape. The question is which way is landscape and which way is reverse landscape? I did not know the answer to this and can’t find the answer online. So I tested it with my phone and found that landscape is when the camera/top-end of the device is on the left. And reverse landscape is when it is on the right.
Display Cutouts
Note, thanks to display cutouts such as notches and pinholes in the display, the display may not be perfectly symmetric between reverse and non-reverse. Display cutouts are a recent trend in the quest for phones to get larger screen-to-body ratios. In the early days of Android, before cutouts, reverse vs non-reverse was always symmetric. Now, arguably, Android’s decision to ignore 180 degree rotations is outdated.
If your app doesn’t draw content in an area that may be covered by a display cutout, the cutout area, then you don’t have to worry about this.
If your app does draw content in a cutout area, and let’s say you allow the user to rotate between landscape and reverse-landscape, then you may have an issue where your important content is full visible before a 180 degree rotation but not after. And since 180 degree rotations do not trigger orientation or config changes, how are you expected to respond to such an event to reposition your content? I’m really not sure how.