How to fix the orientation from androidmanifest?

Just you have to define below property to your activity inside manifest file, It will restrict your activity to portrait.

android:screenOrientation=”portrait”

Example:

        <activity
            android:name="com.example.demo_spinner.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

If you want to do using java code try

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

before you setContentView for your activity in onCreate(). Hope this help and easy to understand for everyone!