Android Question How to freeze the orientation of an Activity - Reflection?

Discussion in 'Android Questions' started by Gary Milne, Mar 23, 2015.

  1. Gary Milne

    Gary Milne Active Member Licensed User

    I have an app that mostly uses Landscape but has one Portrait activity.

    I need to be able to set and freeze the orientation on a per activity basis.

    I've tried Phone.SetScreenOrientation as described here but that does not lock the orientation and it still changes on a device rotation.

    There is a thread that describes how to do this (how to lock orientation during runtime) and it seems like it would be a fit for Reflection but I don't have a good handle on Reflection semantics.

    Is anyone willing to translate it for me or give me a pointer.

  2. Arf

    Arf Active Member Licensed User

    I do this, it works welll:
    Sub Process_Globals
    Dim p As Phone
    End Sub
    If GetDeviceLayoutValues.Width > GetDeviceLayoutValues.Height Then
    0)    'landscape
    1)    'portrait
        End If
    so it just locks the orientation to whatever it was when the activity started.
    Scotter likes this.
  3. NJDude

    NJDude Expert Licensed User

    No need for reflection or phone library, you can set each activity orientation using the manifest editor, let say you have 2 activities, Main and Extra:
    SetActivityAttribute(Main, android:screenOrientation, "portrait")
    SetActivityAttribute(Extra, android:screenOrientation, 
    jimmyF, Scotter, DonManfred and 3 others like this.
  4. Gary Milne

    Gary Milne Active Member Licensed User

    Two great answers, thank you both very much.

    I see why it did not work for me originally, the article I referenced used these constants.
    ' 1 = Portrait' 2 = Landscape' 9 = Reverse Portrait' 8 = Reverse Landscape
    so I was doing p.SetScreenOrientation(2) to try and get landscape and that is now clearly wrong.

    I used the SetActivityAttribute option and it works flawlessly.
    Last edited: Mar 24, 2015
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice