Question:
I am developing an android application and I don't want the screen to be rotated.
How do I disable the screen rotation option in android so that when the phone is rotated it stays vertical?
Answer:
You can do this with the screenOrientation
property within your AndroidManifest.xml
.
<activity android:name=".miActivity"
...
android:screenOrientation="portrait" />
Another option, which involves adding code for each activity, is:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
It is added immediately after onCreate()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
...
...
...
There is currently no way to disable rotation for the entire application. As a "global" solution you could extend all your Activities from a "Parent Activity" that has defined:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);