Android Question Problem with SetScreenOrientation

biometrics

Active Member
Licensed User
Longtime User
Hi all,

We have a media player application that looks at it's playlist file and determines the required orientation.

We use SetScreenOrientation to set the orientation. If the orientation is different from what it is currently the screen is re-orientated and the app restarts as expected.

This has worked fine since we implemented it at the beginning of the year. No code has changed in this regard.

I have been upgrading the compiler as new releases came out though. Currently 5.2.

For the first time today I had to test this feature again and now it doesn't work. The screen is re-orientated but there is nothing visible on the screen (it's on the desktop). The app is still running though (I can trace the code in the IDE and it logs to files etc.)

If the orientation was correct and the app wasn't restarted then the app is visible.

Any idea what is wrong?
 

biometrics

Active Member
Licensed User
Longtime User
I've managed to replicate it in a minimal app, I have two activities named Main and Player.

Start the app with your orientation in landscape. The app with change it to portrait and the image won't be displayed. Now in portrait mode start the app and it will display the image.

Note I'm expecting this file to exist: File.DirRootExternal & "/Player/default.jpg".

Main:
B4X:
#Region Module Attributes
   #FullScreen: True
   #IncludeTitle: False
   #ApplicationLabel: Orientation
   #VersionCode: 1
   #VersionName: 1.0.0
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   StartActivity(Player)
   Activity.Finish
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Player:
B4X:
#Region  Activity Attributes
   #FullScreen: True
   #IncludeTitle: False
#End Region

Sub Process_Globals
   Dim libPhone As Phone
End Sub

Sub Globals
   Dim libImage As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Start
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
  Activity.Finish
End Sub

Sub Start
  libPhone.SetScreenOrientation(1)

  libImage.Initialize("libImage")
  Activity.AddView(libImage, 0, 0, 500, 500)
  libImage.Visible = True
  libImage.Bitmap = LoadBitmap(File.DirRootExternal & "/Player/", "default.jpg")
End Sub
 
Last edited:
Upvote 0

biometrics

Active Member
Licensed User
Longtime User
I have found the cause but I don't know why it's a problem. We don't want our app to be able to sleep.

If I remove Activity.Finish from Activity_Pause then it works correctly.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
You should not be adding Activity.Finish to Activity_Pause. When you call SetSCreenOrientation and the orientation changes, Activity_Pause and Activity_Resume get called
 
Upvote 0

biometrics

Active Member
Licensed User
Longtime User
You should not be adding Activity.Finish to Activity_Pause. When you call SetSCreenOrientation and the orientation changes, Activity_Pause and Activity_Resume get called

Mmm, pretty sure it used to work before. Perhaps the previous compilers treated it differently?

Unless of course I added it sometime during the year. :oops: Can't remember.

Sorted it by by checking UserClosed.

B4X:
Sub Activity_Pause (UserClosed As Boolean)
  If UserClosed Then
    Activity.Finish
  End If
End Sub
 
Upvote 0

biometrics

Active Member
Licensed User
Longtime User
How can I make sure the app never is paused? That it is always destroyed when going to the background.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
In short, you shouldn't. Can you explain in more detail what you are trying to accomplish? Why do you need the activity "destroyed" exactly? If you need the entire app shut down you would use ExitApplication. This will close the entire app though, not just one activity.
 
Upvote 0
Top