Considering screen orientation is essential when creating a good user experience. Imagine having a game on your smartphone that can only be played with the phone facing one direction. Or what if the information entered in a field of an app gets erased every time you rotated the phone? It’s not an ideal user experience. So if you haven’t taken screen orientation changes into consideration when you’re developing your game, this is our next game developer tip. Read on for more details.
Android™ is designed to run efficiently on a wide array of devices with varying hardware configurations. Some devices can change their hardware configuration at runtime, so that, for example, if the device has a keyboard, the screen changes from portrait to landscape orientation.
The Android system automatically handles configuration change events and restarts the current activity. The restart behaviour is designed to help your application adapt to new configurations by automatically reloading your application with alternative resources that match the new device configuration. But this behaviour may be confusing to new Android developers, who may wonder why their activity is destroyed and recreated.
We’ve already seen a few instances where screens have not been oriented properly, and it creates a very poor user experience. Therefore, we strongly suggest that developers do ensure proper screen orientation for their apps, which is our newest tip (AP18) for the Xperia™ Game Developer Recommendations list. The application should take care of orientation changes and allocate appropriate resources accordingly. The orientation of a device can be checked by using:
getResources().getConfiguration().orientation
Also, please remember that an Android activity is restarted by default when an orientation is changed, so you should ensure that activities (saving the state of the application, handling resources) are properly handled.
The Android Developer resources site has more information on the orientation field. And if you have any other questions on how to configure screen orientation, please leave us a comment and we’ll get back to you as soon as possible.
More Information
- Learn more about runtime-changes.
- Read how to make faster screen orientation changes.
- Download the Xperia Game Developer Recommendations PDF.
- Find many more developer tips and guidelines in our Xperia PLAY developer section.
Źródło: Game developer tip 8: Handling screen orientation changes
Category: Sony Ericsson | Tags: None
Related Posts
- No related posts found.
You must be logged in to post a comment.