Here’s a pseudo code to detect screen rotate event, and decide to retain or changes the screen orientation.
public boolean onOrientationChanges(orientation) {
if(orientation == landscape)
if(settings.get("lock_orientation"))
return false; // Retain portrait mode
else
return true; // change to landscape mode
return true;
}
How do I make similar things in Android?
EDIT:
I’m actually looking answer on Where to handle orientation changes. I do not want to fix the orientation by adding screenOrientation=”portrait”.
I need something, similar to onConfigurationChanges(), where I can handle the orientation, but do no need me to manually redraw the view.
You need a
Displayinstance firstly:Then orientation may be called like this:
Check orientation as your way and use this to change orientation:
I hope it helps.
Update:
Okay, let’s say you’ve an
oAllowvar which isBooleanand default value isFalse.You can add more choices.
I didn’t try this sample, but at least tells you some clues about how to solve. Tell me if you got any error.
UPDATE
getOrientation()is already deprecated see here. Instead UsegetRotation(). To check if the device is in landscape mode you can do something like this: