Android Question how to set default orientation to different activities of one project?

Hello!

I am currently working on a project in which i require my main page to be in portrait always or by default while the other activities in the project must also be set in a landscape orientation by default. Can anyone tell me how?
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
This should do the trick:

1. In your globals Dim ph1 as Phone
2. Then in your Activity_Create Sub use ph1.SetScreenOrientation(0)
3. To return your Orientation to previous setting ph1.SetScreenOrientation(1) when you leave your activity in Sub Activity_Pause

B4X:
Sub Globals
    Dim ph1 As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("scrBodyShapeSpreadsheet")
    ph1.SetScreenOrientation(0) '-1 Unspecified, 0 - Landscape, 1 - Portrait 
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    ph1.SetScreenOrientation(1)
End Sub

More information here

As easy as the Internet Ne !!
 
Upvote 0

Thanks it works!
But i think that no.3 can be excluded as long as the #SupportedOrientations is unspecified and the main program will be programmed with ph1.SetScreenOrientation(1) for a portrait orientation while the other activities will be programmed with ph1.SetScreenOrientation(0) for landscape orientation without setting the Sub Activity_Pause with any previous orientations. Setting Sub Activity_Pause actually causes errors/crashes in my program. Thus, I end up excluding no.3 and it actually works well.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…