Rotational Forces, Part Four

In the first three parts of this series, we covered ways for your Android application to cope with rotation events. Some are simple, some are more flexible.

Today, though, we’ll take a look at a radical alternative: tell Android not to rotate your activity at all. If the activity does not rotate, you do not have to worry about writing code to deal with rotations.

To block Android from rotating your activity, all you need to do is add android:screenOrientation=”portrait” (or “landscape”, as you prefer) to your AndroidManifest.xml file, as shown below:

[sourcecode language=”xml”]
package="com.commonsware.android.rotation.four"
android:versionCode="1"
android:versionName="1.0.0">

android:screenOrientation="portrait"
android:label="@string/app_name">







[/sourcecode]

Since this is applied on a per-activity basis, you will need to decide which of your activities may need this turned on.

At this point, your activity is locked into whatever orientation you specified, regardless of what you do. The following screen shots show the activity we developed in the first three posts, using the above manifest, with the emulator set for both portrait and landscape orientation — note that the UI does not move a bit, but remains in portrait mode.

Forced-Portrait Orientation, in Portrait Mode

Forced-Portrait Orientation, in Portrait Mode

Forced-Portrait Orientation, in Landscape Mode

Forced-Portrait Orientation, in Landscape Mode

About author

AndroidGuys
AndroidGuys 4627 posts

Founded on November 5, 2007, we've enjoyed bringing you the latest in Android news and rumors. Updated daily, we strive to deliver reviews, opinions, and updates on all things related to Android.

You might also like

News and Rumors

Best Buy Offering a Pair of Free Samsung Android Handsets April 29-30

Best Buy has brought back their popular Free Phone Friday deals and made them even better.  How?  By tacking on an extra day, that’s how.  This time around Best Buy

News and Rumors

Vizio returns to Android smartphones with pair of Chinese models

Vizio today announced a return to the Android smartphone space, unveiling a pair of handsets bound for China. On one hand you have the upper-echelon stuff in the 5-inch 1080p

News and Rumors

ICS-powered ViewSonic ViewPad G70 leaked, headed for Barcelona?

Last year, ViewSonic introduced a lot of decent tablets, like the ViewPad 7e, ViewPad 7X and ViewPad 730. It looks like Viewsonic is ready to rock in 2012, as our friends