Screen Orientation Problem

mjtaryan

Active Member
Licensed User
Longtime User
In an app I'm working on I have the Project Attributes for screen Orientation in B4a 2.52 set to "unspecified." In Sub ActivityCreate I check the Orientation and load an appropriate layoutdepending on whether It is layout or portrait. I do this in each activity. However, when I compile and running the app, on none of my devices does the app change from one orientation to another. It always remains in portrait. I'very tried to force the app to changes orientations by using the "setscreenorientation"method in the Phone library, but that hasn't worked. How do I solve? Thanks.
 

mjtaryan

Active Member
Licensed User
Longtime User
Are you sure that you haven't blocked the screen rotation on your device ?

Best regards.

I checked before starting the thread. Additionally, the problem occurs on all four of my devices and other apps reorient fine. But I will check again.
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Thanks guys. I haven't done anything to the anifest at all. And I haven't found anything helpful in the documentation
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Then post your code to take a look, otherwise this thread will run forever in a guessing game.

At this point the code consists of a splash screen and a four item "menu" once the splash is hidden. None of the code and those subs affects the orientation. The only code I have that does is the following:

B4X:
Sub Activity_Create(FirstTime As Boolean)

    'Do not forget to load the layout file created with the visual designer. For example:

    'Activity.LoadLayout("Layout1")

    If Activity.Width > Activity.Height Then

        Activity.LoadLayout("SplashL")

        'Added to try to force orientation change when needed.

        Fone.SetScreenOrientation(0)

    Else

        Activity.LoadLayout("Splash")

        'Added to try to force orientation change when needed.

        Fone.SetScreenOrientation(1)

    End If



'    StartActivity(Contents)

    Init

    If FirstTime = True Then

        ShowSplash

    Else

        ShowMenu

    End If



End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Please reread the original post.

And you re-read my response above :D

Ok, let me explain:

Not because you have "unspecified" set on your Manifest means that the device will change orientation in this case, like I said on my previous post, using Fone.SetScreenOrientation(0) forces the orientation to be Landscape (or portrait) so you are locking the orientation to either landscape or portrait, if you remove those lines you will see it will work as intended.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
By doing this:
B4X:
Fone.SetScreenOrientation(0)
You are FORCING the screen to be set as Landscape, therefore, rotating the device will have no effect.

Hwever, as I think I noted in the originak post, these ines were added when the orientation failed to change as expected. Originalky the conditional statement was used only to load the kayout files. When the kines to which you refer are removed the orientation prob in em still exists. It was an attempt to force the device to change that they were inserted before I started the thread.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
A very curious and unusual problem that apparently has/had little or nothing to do with either the app or B4a.

For some reason I thought I'd restart my device. When I did, the problem disappeared on that device. So, one by one I restarted them all and on each the problem vanished. What is curious is that all four of my devices have different versions of Android.

Thanks for the help.
 
Upvote 0
Top