Android Question [Solved]I don't get understand Erel's words about Orientation Screen management,I need a example.

Theera

Expert
Licensed User
Longtime User
Refer to Erel's advice in https://www.b4x.com/android/forum/t...-same-code-phone-or-tablet.73752/#post-468927 ,How do I solved my problem?

My Code Module (SupportedOrientationsScreen) is belows
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
    Public Orientation As String
End Sub

Sub  SelectOrientation As String
    If GetDeviceLayoutValues.Width > GetDeviceLayoutValues.Height Then
        Orientation = "Landscape" 
    Else
        Orientation = "Portrait"
    End If
    Return Orientation
End Sub
My code is belows
B4X:
Sub Activity_Create(firstTime As Boolean)
   

    'put this code in a code module and call it from Activity_Resume of each activity.
    'for SupportedOrientations possible values: unspecified, landscape or portrait
   
   
    Activity.LoadLayout("1")
   
       :::
End Sub



Sub Activity_Resume
    IIf(SupportedOrientationsScreen.SelectOrientation="Portrait",Activity.LoadLayout("1"),Activity.LoadLayout("2"))
        :::
End Sub
 

Theera

Expert
Licensed User
Longtime User
Replace line 8 with line 16.
Assume the user suddenly can change while working. How do I edit the code?(Rotating mobile)
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
You need to remove all views from the layout.
I remember some case which be asked before, I think I may find it
, Thank you, Aeric.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
You need to remove all views from the layout.
After Replaced line 8 with line 16.
B4X:
Sub Activity_Resume
'reset screen Orientation
    Activity.RemoveAllViews
    Activity_Create(False)
   :::
End Sub
P.S.
B4X:
    IIf(SupportedOrientationsScreen.SelectOrientation="Portrait",Activity.LoadLayout("1"),Activity.LoadLayout("2"))  'Not Worked
'------------------------------------------------------------------------------------------------
   If  SupportedOrientationsScreen.SelectOrientation="Portrait" then  'Worked
         Activity.LoadLayout("1")
   Else
        Activity.LoadLayout("2")
   End If

Thank you ,Areric again. ArericGPT is fast answer. I like this GPT.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Try changing
B4X:
IIf(SupportedOrientationsScreen.SelectOrientation="Portrait",Activity.LoadLayout("1"),Activity.LoadLayout("2"))  'Not Worked

to
B4X:
Activity.LoadLayout( IIf(SupportedOrientationsScreen.SelectOrientation="Portrait","1","2"))
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Try changing
B4X:
IIf(SupportedOrientationsScreen.SelectOrientation="Portrait",Activity.LoadLayout("1"),Activity.LoadLayout("2"))  'Not Worked

to
B4X:
Activity.LoadLayout( IIf(SupportedOrientationsScreen.SelectOrientation="Portrait","1","2"))
Thank you for kind of you, Daestrum
 
Upvote 0
Top