Android Question Lock orientation in manifest or in Project Attributes. How to

Gianni Sassanelli

Active Member
Licensed User
Longtime User
Hi,
i need to Lock orientation in manifest or in Project Attributes depend on device type

for example something like:
If device is tablet
#SupportedOrientations: landscape
else
#SupportedOrientations: portrait
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Try adding the code to check orientation and set the value in your activity_create block. If I recall correctly setting the orientation prevents it from changing.
 
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
IN ACTIVITY_CREATE I have inserted the following code but some times user manages to turn the device and this causes crashes of the activity
If i prevent this in #Region Project Attributes of main prg, everything is right


B4X:
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Dim p As Phone
IF LV.ApproximateScreenSize > 6.6 then
    p.SetScreenOrientation(0)
else
    p.SetScreenOrientation(1)
end if
Activity.LoadLayout("MYLAYOUT")
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Maybe try adding
B4X:
Sleep(0)
before your LoadLayout and see if that prevents the crash? Without knowing what the crash error is it is difficult to give suggestions.
 
Last edited:
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
I have a Home Activity that use as menù and from it I call other activity

for example, from button1_click of my home i do:
B4X:
callsubdelayed("activity2","on_start")


' in activity2

Sub Process_Globals
    Dim SF As StringFunctions
    Dim P As Phone
End Sub
Sub Globals

    Dim ULV                         As UltimateListView  'Griglia --> Grid
    Dim mpULV                     As Map         
    Dim ULV_LS                    As List                    'Vettore della lista --> RecordSource
    Dim ItemHeight                As Int                    'Altezza delle righe
    Dim hj                         As HttpJob
    Dim lsJOB                     As List
    Dim mpWork                    As Map
    Dim mapJOB                     As Map
    Dim BD                         As BetterDialogs

End Sub


Sub Activity_Create(FirstTime As Boolean)
    If Main.oapp.Is_Tablet Then
        p.SetScreenOrientation(0)
        Activity.LoadLayout("lay_sincro_dati")
    Else
        p.SetScreenOrientation(1)
        Activity.LoadLayout("lay_sincro_dati_p")
    End If
    lsJOB.Initialize
    mapJOB.Initialize
    SF.Initialize
    ULV_Init  
End Sub


sub on_start
   ' some code
   ' the program crash here becouse if the user move the device,
   ' set screen orientation reset all the view and
   ' i have some errors where i try to bound the label, edittext ecc with data received from Web api.
 

    ulv_load_data  ' load data from web_api
    ....
end sub



Now i have solved added SLEEP(1000) in on_start SUB
 
Upvote 0
Top