how to stop screen rotation in android code

Java
<!-- inside of your AndroidManifest.xml -->
<activity android:name=".MainActivity"
		  android:screenOrientation="portrait"/><activity
        ...
        ...
        android:screenOrientation="nosensor">android:screenOrientation="portrait" 
Source

Also in Java: