Android Question Stopping app from changing orientation

james_sgp

Active Member
Licensed User
Hi, I have an app that is only designed to be used in portrait mode; but how do I stop it from recreating when the device is turned?
I have set Project Attributes, '#SupportedOrientations: portrait'; I have tried the 'phone1.SetScreenOrientation(1)' but the screen still rotates and kills my apps activity (i assume) and the screen goes white and the app sits there. Even rotating back to portrait the screen is not re-appearing.

Appreciate any advice...James
 

DonManfred

Expert
Licensed User
you can set this setting if a activity (or more than just one) should only run in a specific orientation.
Note that you need to have one entry for any activity you want it fixed.
B4X:
SetActivityAttribute(servicemain, android:screenOrientation, "portrait")
SetActivityAttribute(Main, android:screenOrientation, "portrait")
SetActivityAttribute(Abnahme, android:screenOrientation, "portrait")
but the screen still rotates and kills my apps activity (i assume) and the screen goes white and the app sits there. Even rotating back to portrait the screen is not re-appearing.
Upload a small project which shows the issue. Otherwise it is hard to help.
Make sure to load the activity layout not just when firsttime is true.
 

JohnC

Well-Known Member
Licensed User
You can also set/force the orientation programmically at runtime:

B4X:
Sub SetScreenOrientation(LandScape As Boolean, Reverse As Boolean)
    Dim MyPhone As Phone
    If LandScape = False Then
        If Reverse = False Then
            MyPhone.SetScreenOrientation(1)       
        Else
            MyPhone.SetScreenOrientation(9)
        End If
    Else
        If Reverse = False Then
            MyPhone.SetScreenOrientation(0)
        Else
            MyPhone.SetScreenOrientation(8)
        End If
    End If
End Sub
 

james_sgp

Active Member
Licensed User
You can also set/force the orientation programmically at runtime:

B4X:
Sub SetScreenOrientation(LandScape As Boolean, Reverse As Boolean)
    Dim MyPhone As Phone
    If LandScape = False Then
        If Reverse = False Then
            MyPhone.SetScreenOrientation(1)      
        Else
            MyPhone.SetScreenOrientation(9)
        End If
    Else
        If Reverse = False Then
            MyPhone.SetScreenOrientation(0)
        Else
            MyPhone.SetScreenOrientation(8)
        End If
    End If
End Sub
John,

I tried that and it doesn`t work...
 

james_sgp

Active Member
Licensed User
you can set this setting if a activity (or more than just one) should only run in a specific orientation.
Note that you need to have one entry for any activity you want it fixed.
B4X:
SetActivityAttribute(servicemain, android:screenOrientation, "portrait")
SetActivityAttribute(Main, android:screenOrientation, "portrait")
SetActivityAttribute(Abnahme, android:screenOrientation, "portrait")
Upload a small project which shows the issue. Otherwise it is hard to help.
Make sure to load the activity layout not just when firsttime is true.
Thanks, I have 6 different layouts...they are all called 'Activity' would that cause a problem or is it better to rename them all and put multiple entries into the manifest?
 

JohnC

Well-Known Member
Licensed User
John,

I tried that and it doesn`t work...
Did you try calling this routine from the Activity_Create sub (before you load the layout)?
 

james_sgp

Active Member
Licensed User
you can set this setting if a activity (or more than just one) should only run in a specific orientation.
Note that you need to have one entry for any activity you want it fixed.
B4X:
SetActivityAttribute(servicemain, android:screenOrientation, "portrait")
SetActivityAttribute(Main, android:screenOrientation, "portrait")
SetActivityAttribute(Abnahme, android:screenOrientation, "portrait")
Upload a small project which shows the issue. Otherwise it is hard to help.
Make sure to load the activity layout not just when firsttime is true.
Ok, I just made a simple program that displays a label on the screen and used your Manifest entry...nothing happens screen still rotates.
 

Attachments

james_sgp

Active Member
Licensed User
This file is a incomplete/unuseable project; no layouts, no other activities, no manifesttext changes...

HOW should we help here?

Use FILE-Export as zip from the IDE
Sorry, zipped the wrong thing. Didn`t see the built in zip function...anyway here is the file.
 

Attachments

DonManfred

Expert
Licensed User
.anyway here is the file
Logger connected to: 988ad036525346515630
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
I can orient my device as i wish....There is no Activity recreated.
 

Semen Matusovskiy

Well-Known Member
Licensed User
#SupportedOrientations is not alone, which defines actual orientation.

For example, SetActivityAttribute(Main, android:screenOrientation, "landscape") in manifest will have a priority over portrait in #SupportedOrientations.

There are also extra priority "Quick settings" in the top of the screen. If smartphone uses "clean" Android, the behaviour is clear. But custom firmwares maybe enough exotic.
 

klaus

Expert
Licensed User
The video you show is not the test project fom your post#10, why?
I test it also on my 10' tablet Samsung Galaxy Tab S2, and it works as expected.
Have this project?
 

james_sgp

Active Member
Licensed User
Yes it is the project i uploaded...
What version of Android is it using, im wondering if thats the problem...? I cant think of another reason why my app would act differently for me n you?
 

klaus

Expert
Licensed User
Yes it is the project i uploaded...
Sounds strange, because when I run the project the title line shows Activity and not Mobile POS like in the video.
The Label with 'Text' insides is also missing !?

My tablet has Android version 7.0.
 

james_sgp

Active Member
Licensed User
Sounds strange, because when I run the project the title line shows Activity and not Mobile POS like in the video.
The Label with 'Text' insides is also missing !?

My tablet has Android version 7.0.
Klaus,
OK, the link to the video of my actual app, not the test app (with "TEST" text). Here is the link to the test app I had posted...

https://app.box.com/s/ovcwa7efbe9upff2y0dhr359af0b7k7v

But shows the same thing, the screen rotates when I rotate my tablet. Is there a chance its to do with my SDK settings? If so I`ve attached screenshots of those.
 

Attachments

james_sgp

Active Member
Licensed User
Klaus,

Thanks I wasn`t aware of the change with the SDK, I`m now installing the new version hopefully it helps.

James
 
Top