Android Question Change Orientation automatically only one time...

Magma

Expert
Licensed User
Longtime User
Hi there,

I want user decide at what orientation will work (so i am using unspecified) but i want to decide it before run for first time my application.

So i want to stop him change again and again the orientation - only at first time loading the app...

How will do that ?

Thanks in advance
 

NJDude

Expert
Licensed User
Longtime User
When the user runs the app for the first time, show a dialog asking for the preferred orientation and then set it using SetScreenOrientation (Phone library), you can save their choice in a INI file or something which will be read the next time the app runs and set the orientation accordingly.

That's an idea.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
use can use Preferences, (see this) this library allows you to create the "standard" settings screen:

Create Preferences screen:
B4X:
Dim screen As PreferenceScreen

screen.Initialize("Settings", "")
 
Dim catGeneral As PreferenceCategory

catGeneral.AddList("LockScreenOrientationMode", "Lock the screen in portrait or landscape mode", "Select to Lock the screen in portrait or landscape mode",  "Auto (Unlocked)", _
        Array As String("Auto (Unlocked)", "Portrait", "Landscape", "Reversed Portrait", "Reversed Landscape"))

screen.AddPreferenceCategory(catGeneral)

read preferences where you want:
B4X:
    Dim manager As PreferenceManager

    Dim setting_LockScreenOrientationMode As Int
....
Try
        Select manager.GetString("LockScreenOrientationMode")
            Case "Auto (Unlocked)"
                setting_LockScreenOrientationMode = -1
            Case "Landscape"
                setting_LockScreenOrientationMode = 0
            Case "Portrait"
                setting_LockScreenOrientationMode = 1
            Case "Reversed Landscape"
                setting_LockScreenOrientationMode = 8
            Case "Reversed Portrait"
                setting_LockScreenOrientationMode = 9
        End Select
    Catch
        setting_LockScreenOrientationMode=-1
    End Try


then you can set orientation in activity_create:
B4X:
Sub Activity_Create(FirstTime As Boolean)

    Dim phone1 As Phone
    phone1.SetScreenOrientation (setting_LockScreenOrientationMode)
    ....
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
may be i wasn't so exact...

but you are close at what i want..

when start the activity automatically (automatically) change only for only one time the orientation and the keep it lock...

if there is a way to get the type orientation ? and then lock it...
 
Upvote 0
Top