Screen orientation and values in manifest.xml

If you want to have fixed orientation for your activities then you can use-

android:screenOrientation="portrait"

android:screenOrientation="sensorPortrait"

as an attribute to that activity in that manifest. But if you want to set the orientation runtime depending upon what was the previous orientation while launching the application, you need to check for the previous orientation in onCreate() and then set it to that value programmatically there itself using setRequestedOrientation()

UPDATE: As pointed by @s.co.tt use android:screenOrientation="sensorPortrait" for a better support on tablets.

For more details on the different values for android:screenOrientation and what each of them do, look at the docs:

https://developer.android.com/guide/topics/manifest/activity-element.html#screen


<activity
            android:name=".Android_mobile_infoActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
  </activity>