Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen orientation and values in manifest.xml

Tags:

I want to use all activities in my form in landscape or portrait. When user select orientation - this is valid for all activities. Tried with "behind" option orientation. According to Google - orientation will depend on previous activity.

My first activity use setRequestedOrientation to set selected from user orientation.

Next activities have to follow same orientation. Do I have to put setRequestedOrientation in their code too? Or really on 'behind' parameter in manifest? Putting setRequestedOrientation may be cause onCreate again?

UPDATE:
Tried "portrait" and setRequestedOrientation() - result is onCreate was called 2 times.

Problem is in next activity -> because of "portrait" in first activity - android started next activity with same orientation. It ignores "landscape" orientation which was set by me.

like image 909
Kostadin Avatar asked Mar 21 '12 09:03

Kostadin


People also ask

What is screen orientation full sensor?

I have read the document ,when I write android:screenOrientation="sensor" in ,that means the orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.

Where do we define orientation of activity?

The orientation of android activity can be portrait, landscape, sensor, unspecified etc. You need to define it in the AndroidManifest. xml file. Your screen will always display in Landscape mode, when you rotate your device, no changes will apply for the current activity.


1 Answers

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

like image 179
Rajkiran Avatar answered Nov 01 '22 09:11

Rajkiran