How do I detect screen rotation

You are correct that at a 180 degree rotation you will not get restarted or get a configuration change, because the configuration has not actually changed. (It is still in landscape or portrait, and everything else is the same.)

However if you are showing a compass, that must mean you are updating it from sensor events. Thus you can just call Display.getRotation() each time you get a sensor update to get the current rotation of the screen. In fact that you need is rotation of interpreting sensor events (or actually how your drawing of them will be modified when it gets to the screen), not just the orientation.

I found a relevant blog post that is well worth reading.

Be sure to read the SDK documentation.

Also check out the discussion about using Display.getRotation() to correctly remap sensor coordinates.

Leave a Comment