Android Question Stopping app from changing orientation

james_sgp

Active Member
Licensed User
Longtime 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
Longtime 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.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime 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
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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...
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime 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)?
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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

  • Orient test.zip
    1 KB · Views: 153
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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

  • Orien Test.zip
    9 KB · Views: 176
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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.
 
Upvote 0

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.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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?
 
Upvote 0

klaus

Expert
Licensed User
Longtime 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.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime 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

  • Capture0.PNG
    Capture0.PNG
    83.4 KB · Views: 149
  • Capture1.PNG
    Capture1.PNG
    82.6 KB · Views: 147
  • Capture2.PNG
    Capture2.PNG
    68.3 KB · Views: 143
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Klaus,

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

James
 
Upvote 0
Top