Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent change of orientation when device is tilted?

Tags:

android

How can I prevent the activity from redrawing in the new orientation out when the device is tilted? I want the onCreate function to not execute a second time after the activity has been shown.

like image 977
Raj Avatar asked Aug 24 '11 11:08

Raj


2 Answers

If you want to cope with tablet devices then you should use the nosensor value instead, e.g.

<activity android:name=".MyActivity" 
          android:screenOrientation="nosensor" ></activity>

This will use the natural orientation for the device, which will be landscape on some devices (e.g. the Xoom tablet).

API docs for this are here:

The orientation is determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.

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

like image 108
Dan J Avatar answered Oct 08 '22 11:10

Dan J


you can fix the screen orientation. Add this to your activity tag in your manifest file:

android:screenOrientation = "portrait"
like image 43
Vineet Shukla Avatar answered Oct 08 '22 11:10

Vineet Shukla