0

I'm developing an app that only some pages can be displayed on landscape orientation, I do not want to lock the screen on display, I wish to deny Android do a orientation change.

There's something that I can use for it? Like, at runtime on orientation change, Android asks if it's possible to go to that orientation?

If there's not, how can I lock the current screen orientation? I know that setRequestedOrientation can do that, but it implies in discover the current orientation (and even discover the correct orientation like 'normal' or 'inverse' portraits/landscapes) and lock to it.

EDIT: There's only ONE activity on this app, and based on it's state (that changes trough time and user input) it can be rotated or not, that is my problem.

As seen at http://developer.android.com/guide/topics/resources/runtime-changes.html about configuration changes:

"Handle the configuration change yourself Prevent the system from restarting your activity during certain configuration changes, but receive a callback when the configurations do change, so that you can manually update your activity as necessary."

Even with that the configuration changes, I wish to block this behavior before that.

Marcos Vasconcelos
  • 17,773
  • 29
  • 104
  • 165
  • 1
    Duplicate of http://stackoverflow.com/questions/2150287/force-an-android-activity-to-always-use-landscape-mode ? – Brian Nickel Jun 20 '12 at 18:33
  • Just to add to what @BrianNickel said, [this answer](http://stackoverflow.com/a/2150558/1438733) is probably what you're looking for. You may also want to look into [this](http://stackoverflow.com/questions/1512045/how-to-disable-orientation-change-in-android). – Eric Jun 20 '12 at 18:36
  • My question is how to deny on runtime the device to not change the orientation – Marcos Vasconcelos Jun 20 '12 at 18:43
  • I tried some onConfigurationChanges approach not working, even if I consume the event the screen rotates and displays the old orientation rotated, but this also make my screen do not recreate the Views, and it's important too. – Marcos Vasconcelos Jun 20 '12 at 18:53
  • 1
    "Even with that the configuration changes, I wish to block this behavior before that" -- that is not possible, short of writing your own custom firmware. You cannot stop the configuration from changing. At most, you manage the *effects* of a configuration change. – CommonsWare Jun 20 '12 at 19:52
  • Well, it's not possible, so I used the setRequestOrientation solution. – Marcos Vasconcelos Jun 20 '12 at 22:46

1 Answers1

3

Add one othese to each activity.

public void checkActivityPos() {

    if(somthing == "this") {
        myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }else {
        myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}