Let's say my app has two activities A
and B
. And, also, let's call the posible screen orientations landscape-1
, portrait-2
, landscape-3
and portrait-4
.
I would like to lock the orientation of A
to landscape (1
and 3
), and B
to both landscape and portrait (1
, 2
, 3
and 4
).
So, to do this, I used sensorLandscape
. Later I realized that sensorLandscape
is for API 9 or greater, and I want to support older versions. I searched for a way to emulate sensorLandscape
behaviour, but I didn't find anything. So I'm now going for a simpler approach: I would like to use landscape
mode on activity A
(this is, just 1
), but I don't want the user to be able to use landscape-3
on activity B
(so there's no weird turning when going back to activity A
).
To sum up, the idea is the following:
Posible screen orientations for activity A
: landscape-1
.
Posible screen orientations for activity B
: landscape-1
and portrait-3
.
Any ideas on how to accomplish this behaviour?
Asked
Active
Viewed 529 times
0

user4830843
- 41
- 4
-
Forcing orientation lock for Activity B is pointless and will possibly cause user annoyance. If you're going to support landscape & portrait for Activity B then just let the user decide which orientation they want (landscape, inverse landscape, portrait, inverse portrait).- in other words don't try to lock orientation at all. As for Activity A, again you could cause user annoyance if you only support one landscape mode - fine, force landscape-only orientation if you need to but support both landscape and inverse landscape. – Squonk May 04 '15 at 04:15
-
I would love to do that, that's what `sensorLandscape` does. But I can't use it because I need to support older devices. Do you know how can I emulate `sensorLandscape` behaviour? – user4830843 May 04 '15 at 04:22
-
Look in to setting orientation dynamically in your Activity code. Check for API version and then set orientation depending on that - if the API > 9 then you should be able to detect current device orientation. Activity B can (and should) be allowed to do its own thing automatically adjusted by the OS and actual device orientation. – Squonk May 04 '15 at 04:48
1 Answers
0
Use it and don't support api <13 just because no need to make extra work
Done is better than perfect
Don't worry you are still targeting 97% of Android Users with Api >=9.

Ilja KO
- 1,272
- 12
- 26
-
I can't afford that. In my country, many people use cellphones with lower APIs. – user4830843 May 04 '15 at 04:19
-
You don't write apps for the people of your country but for the world...I can't imagine that there are many users in your country with a pis lower than Android 4.0 – Ilja KO May 04 '15 at 04:33
-
But a workaround would be to use the sensor manager and ask the force of the x and y axis – Ilja KO May 04 '15 at 04:36
-
It's for a strictly local use. The app is not intended to the whole world, it would make no sense. Can you elaborate on that workaround? – user4830843 May 04 '15 at 04:41