I've come across a situation which I need help with.
I have an app with #SupportedOrientations: unspecified
If the device is in landscape mode and I rotate the device about its horizontal axis (so that it stays in landscape mode) then at a roll of about 35deg the screen will flip - but Pause/Resume do not fire.
Similarly if the device is in portrait mode and I rotate the device about its vertical axis (so it stays in portrait mode) then at a pitch of about 35deg the screen will flip - again Pause/Resume do not fire.
Because Pause/Resume do not fire I have no absolute way of detecting the screen flip has happened.
I need to know when this happens because I am using a barcode reader library whose preview gets screwed up when the screen flips and I need to reinitialize the library to correct this.
I have played around with monitoring pitch and roll via Phone.PhoneOrientation and this works after a fashion but it is problematic in 2 ways:
(1) You have to pick a threshold pitch/roll at which to do the barcode library re-initialization - I have established purely by experimentation that 35-40 deg works on my Samsung S5 - but what if it is different on other devices?
(2) It is essential that the barcode library re-initialization occurs after the screen flips - meaning the threshold of (1) has to be correct otherwise you achieve nothing.
Nope - if you rotate the phone as I have indicated above so that the orientation does not change from either landscape or portrait then the screen flips without firing Pause/Resume.
Thanks for your response but no - I am not touching the manifest in any way.
I have attached a really simple project.
(1) Compile and run it.
(2) Turn the phone to landscape - log will show Pause/Resume fired.
(3) Rotate the phone about its long (i.e. horizontal axis) without it getting out of landscape mode.
(4) At some point the screen will flip - but Pause/Resume do not fire.
You are correct. I misread your previous post. The activity will not be recreated if the change is from landscape to reverse landscape (or portrait to reverse portrait).
You can use this code to get the current orientation:
B4X:
Sub GetOrientation As Int
Dim jo As JavaObject
jo.InitializeContext
Return jo.RunMethodJO("getSystemService", Array("window")).RunMethodJO("getDefaultDisplay", Null).RunMethod("getOrientation", Null)
End Sub
No event will be raised. You can use a timer to check this every 100ms. It will be more efficient (and simpler) than monitoring the orientation sensor.