Android Question Is Incrorrect Activity.Height Still An Issue?

Jeffrey Cameron

Well-Known Member
Licensed User
I've been experiencing an odd bug where the Activity.Height is reporting full-screen size even when I have a status bar visible. I found a post from 2013, stating that switching between full-screen/not full-screen (which I am doing in a few activities, no title bar in any of the cases) can cause the incorrect Activity.Height to be reported, is this still a known issue?

I'm using B4A 9.8 on a generic tablet running Android 8.1.0 (with a soft-button bar), no attributes in the manifest relating to immersive mode or custom themes or anything like that. I'm manually adding panels to the activity via Activity.AddView(MyPan, 0, 0, Activity.Width, Activity.Height) and then loading anchored layouts into the panels.

What is odd is that I can write a small test app with 3 activates, (not full, with title, not full without title, and full screen no title) which works fine switching between activities. It's only in the full app that I'm getting the problem. My app goes from Main (not-full-no-title) -> Activity 1 (full-no-title) -> Activity 2 (not full-no title) and the last activity still reports the full-screen size without the status bar. Even using in-line Java with getWindowVisibleDisplayFrame method returns a full-screen dimension.

If I add the activity from the test app (Not full, no title) that reports correctly directly to my full app, and then change the chain to go from Main->Activity 1->TestActivity then the test activity will report the incorrect Activity.height.

I'm out of ideas of what to try other than saving the various min/max values along the way and using those in lieu of the actual activity values. Any suggestions would be welcome.
 

Jeffrey Cameron

Well-Known Member
Licensed User
Ok, I've been playing with the test project and I've managed to reproduce the behavior in the test program. It seems to be related to using StartActivity… followed by Activity.Finish (this was the only difference I could see between my test program and my full app).

The full app uses Main to secure permissions and wait for starter service to fully initialize, after that it starts Activity1 and finishes. Activity1 issues several HTTP requests to the back end server (device authentication, non-volatile configurations, etc.) and assuming all goes well it starts Activity2 which is the main logic and then finishes. Activity2 runs from then on until the app is exited.

The attached test app mimics that, you can play with various combinations of starting main/2/3 and see when the line at the bottom of the screen becomes hidden. Is this an issue on my customer's cheap tablets, an issue because of the soft-button or something more fundamental than either of those?
 

Attachments

  • TestMetrics.zip
    10.6 KB · Views: 67
Upvote 0

Erel

Administrator
Staff member
Licensed User
Why aren't you creating the layout with the designer? It would have been easier to test it.

The switching between non-full screen activities to full screen activities still exists on some devices.

I've uploaded an updated test project. Do you see the green borders in the two activities?
 

Attachments

  • TestMetrics.zip
    9.5 KB · Views: 68
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Why aren't you creating the layout with the designer?
I am. The activity may display several screens during its course, it is simpler to create a list of full-screen panels (all of which use layouts with anchored controls) and switch between them. The problem is when the panel that is created to activity.height is larger than actual working area of the display; anchored controls are being clipped at the bottom of the display by the height of the status bar.

I will check your test program on the customer's device first thing Monday when I'm back in the office. Thank you for taking a look at it!
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Ok, the test program you uploaded works correctly. As I indicated in my post #2 about the test program working but the actual app not working the problem arises when you chain from activity-to-activity by using StartActivity(…) followed by Activity.Finish.

I can cause the test program to fail by adding an "Activity.Finish" after the StartActivity in each module:
Main:
B4X:
Private Sub Activity_Click
 StartActivity(actTwo)
 Activity.Finish 
End Sub
actTwo:
B4X:
Private Sub Activity_Click
 StartActivity(Main)
 Activity.Finish 
End Sub
Those two changes will cause the bottom green bar to be pushed off the screen.

Blame the device and move on, or is something amiss?
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Try to add Sleep(300) between them
If by them you mean:
B4X:
Private Sub Activity_Click
 StartActivity(Main)
 Sleep(300)
 Activity.Finish 
End Sub
That breaks the program completely, when you go back to Main from actTwo the app closes (I assume the sleep is activating and finishing the activity).
B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (acttwo) Create, isFirst = true **
** Activity (acttwo) Resume **
sending message to waiting queue (sleep)
** Activity (acttwo) Pause, UserClosed = false **
running waiting messages (1)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (acttwo) Resume **
** Activity (acttwo) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
upload a modified version of my example that doesn't work properly
Attached is your test program with the two changes I indicated in post #5.
Here are my results visually
metrics.jpg
 

Attachments

  • TestMetrics.zip
    9.5 KB · Views: 65
Upvote 0

Erel

Administrator
Staff member
Licensed User
I see it too. The problem is in the switch to the activity with status bar. You can solve it with this code:
B4X:
Sub Globals
    Private UpdatedHeight As Int
    Private xui As XUI
    Private Base As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim ime As IME
    ime.Initialize("ime")
    ime.AddHeightChangedEvent
    UpdatedHeight = 100%y
    Base  = xui.CreatePanel("")
    Sleep(100)
    Activity.AddView(base, 0, 0, 100%x, UpdatedHeight)
    base.LoadLayout("1")
End Sub

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

Private Sub Activity_Click
    StartActivity(actTwo)
    Activity.Finish 
End Sub
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
That fix may work for the test program, but is problematic for my actual app as activity resume is invoked before activity create is completed and the resume needs view/class objects that are created in the activity_create. This problem can be illustrated in the test program by adding the Activity_Resume block and adding log statements:
B4X:
Logger connected to:  Tablet_Express K10
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Activity_Create started
** Activity (main) Resume **
Activity_Resume Entered
Activity_Resume exited
Activity_Create Resumed
Activity_Create exited
As you can see the event order becomes problematic with this solution. Would moving the panel creation logic to resume sub create issues, or would that be alright?

It should also be noted that the Activity.Height never reports correctly in the activity, in my case it shows 728 and the IME reported 692. I added a label to the test program's designer layout to show these two values and playing with switching between activities more, I can still get the create to finish before the IME event has fired causing the problem to persist. Increasing the sleep delay would seem to be treating the symptom rather than curing the problem.
B4X:
** Activity (main) Create, isFirst = false **
Activity_Create started
** Activity (main) Resume **
Activity_Resume Entered
Activity_Resume exited
IME heightchanged values are (New, Old): 692,728
Activity_Create Resumed
Activity_Create exited
** Activity (main) Pause, UserClosed = true **
** Activity (acttwo) Create, isFirst = false **
** Activity (acttwo) Resume **
** Activity (acttwo) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
Activity_Create started
** Activity (main) Resume **
Activity_Resume Entered
Activity_Resume exited
Activity_Create Resumed
Activity_Create exited
IME heightchanged values are (New, Old): 692,728
 

Attachments

  • TestMetrics.zip
    10.1 KB · Views: 83
Last edited:
Upvote 0

Erel

Administrator
Staff member
Licensed User
It should also be noted that the Activity.Height never reports correctly in the activity, in my case it shows 728 and the IME reported 692. I added a label to the test program's
You need to use the height of the base panel instead.

Activity_Resume will indeed be called before the layout is loaded, however this should not be an issue.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log("Activity_Create started")
    Dim ime As IME
    ime.Initialize("ime")
    ime.AddHeightChangedEvent
    UpdatedHeight = 100%y
    Base  = xui.CreatePanel("")
    Sleep(100)
    Activity.AddView(Base, 0, 0, 100%x, UpdatedHeight)
    Base.LoadLayout("1")
    Label1.text = "Activity.Height = " & Activity.Height & " and IME height reported " & UpdatedHeight
    Activity_Resume
End Sub

Sub Activity_Resume
    If Label1.IsInitialized = False Then Return    
    'do whatever you need here
End Sub
 
Upvote 0
Top