Android Question Activity height not set to correct value if app started with screen off

CaptKronos

Active Member
Licensed User
Longtime User
I think the following issue is related to the one reported here https://www.b4x.com/android/forum/threads/is-incrorrect-activity-height-still-an-issue.114435/. However, I am seeing the problem when an app is started with the device's screen off. I discovered the issue because my app runs in the background and can restart itself (hence the screen is usually off when the app starts). To replicate the scenario, run the attached project, connect your device to the B4A IDE, turn off the device's screen and start the app via the IDE.
The MainPage layout is created in the Designer and consists of a single panel, with a red border, that is resized by the Designer to fill the activity. Starting the app with the screen on, the border is displayed as expected. Starting the app with the screen off, the bottom border is lost. As per the above linked thread, the Activity height doesn't seem to be set correctly with the screen off. The problem can be partially addressed by using the approach Erel suggested in the above thread (using ime_HeightChanged and manually setting the layout) however, relying on the Designer to size the layout will not work when the app is started with the screen off.
B4X:
Sub Class_Globals
    Private Root As B4XView
End Sub

Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Sub B4XPage_Appear
    Log("root height=" & Root.Height)
End Sub


Started with the screen on:
Screenshot_20221223-110543.jpg


Started with the screen off:
Screenshot_20221223-110521.jpg



Adding Erel's IME suggestion:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private updatedHeight As Int
End Sub

Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dim ime As IME
    ime.Initialize("ime")
    ime.AddHeightChangedEvent
    updatedHeight = 100%y
    Root.LoadLayout("MainPage")
End Sub

Sub B4XPage_Appear
    Log("root height=" & Root.Height)
    Log("updated height=" & updatedHeight)
End Sub

Sub ime_HeightChanged (NewHeight As Int, OldHeight As Int)
    updatedHeight = NewHeight
End Sub

Which produces, when starting with the screen on:
root height=1851
updated height=1851



When started with the screen off:
root height=1995
updated height=1995

and then turning the screen on:
root height=1995
updated height=1851

Root height never takes on the correct value of 1851.
 

Attachments

  • Project.zip
    13.4 KB · Views: 156

Sagenut

Expert
Licensed User
Longtime User
I think that the problem is that you have the Soft Touch Commands on your device.
So if you start the app with the display ON the height of the Soft Touch will be considered.
When the display is OFF it will not be considered.
You could consider to switch to IMMERSIVE MODE to remove the Soft Touch when your app is launched.
Check this:
Immersive Mode
Check even this to support the Notch Camera:
Immersive Mode with Notch Support
If instead you want to maintain the Soft Touch you should try to relevate if the display is ON or OFF and manage to load the layout size.
 
Upvote 0

CaptKronos

Active Member
Licensed User
Longtime User
I think that the problem is that you have the Soft Touch Commands on your device.
So if you start the app with the display ON the height of the Soft Touch will be considered.
When the display is OFF it will not be considered.
You could consider to switch to IMMERSIVE MODE to remove the Soft Touch when your app is launched.
Check this:
Immersive Mode
Check even this to support the Notch Camera:
Immersive Mode with Notch Support
If instead you want to maintain the Soft Touch you should try to relevate if the display is ON or OFF and manage to load the layout size.
Currently, I'm going with your final option, and just draw the layout manually. It's not a big deal but it would be nice if there was a way to 'refresh' the app so that the activity detects the correct dimensions.
 
Upvote 0
Top