Android Question 100%y or Activity.height have wrong values after Activity_Resume [SOLVED]

jmon

Well-Known Member
Licensed User
Longtime User
Hello,


When I lock my phone, then unlock it, the values of 100%y and Activity.height at Activity_Resume are wrong. When I close the app, or switch application, the values are correct.

My code is a simple line like this (I use XCustomListView):
B4X:
xlv.sv.SetLayoutAnimated(250, xlv.sv.Left, xlv.sv.Top, xlv.sv.Width, 100%y - pnlTop.Height - pnlBottom.Height - AdsOffset)

If I Log at Activity_Create, the values are:
B4X:
Log(100%y) = 1737
Log(Activity.Height) = 1737

but after lock / unlock the values are:
B4X:
Log(100%y) = 1018
Log(Activity.Height) = 1018

I tried resizing later with CallSubDelayed, it has the same problem.

What can it be?
 

jmon

Well-Known Member
Licensed User
Longtime User
I forced the program to be in portrait mode. These are the values for the width:
B4X:
Log(100%y) = 1737
Log(100%x) = 1080
Log(Activity.Height) = 1737
Log(Activity.Width) = 1080

After unlock:
B4X:
Log(100%y) = 1018
Log(100%x) = 1080
Log(Activity.Height) = 1018
Log(Activity.Width) = 1080

[edit]:
this is how I call the layout for the activity:
B4X:
Activity.LoadLayout("Main")
Nothing changes the size of my layout.

[edit]:
if I set a timer, and call that line 1 second later, I get the correct values.
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Try to use
B4X:
Sub GetActivityWidth As Int

    Dim javaobjectInstance                                                      As JavaObject

    javaobjectInstance.InitializeContext
    Return javaobjectInstance.RunMethod ("getActivityWidth", Null)

End Sub

Sub GetActivityHeight As Int

    Dim javaobjectInstance                                                      As JavaObject

    javaobjectInstance.InitializeContext
    Return javaobjectInstance.RunMethod ("getActivityHeight", Null)

End Sub

#If Java
    import android.graphics.Rect;
    public int getActivityWidth  () { Rect rectangle = new Rect (); getWindow ().getDecorView ().getWindowVisibleDisplayFrame (rectangle); return rectangle.right  - rectangle.left; }
    public int getActivityHeight () { Rect rectangle = new Rect (); getWindow ().getDecorView ().getWindowVisibleDisplayFrame (rectangle); return rectangle.bottom - rectangle.top;  }
    public int correctLayout () { mostCurrent.layout.getLayoutParams ().height = getActivityHeight (); mostCurrent.layout.getLayoutParams().width = getActivityWidth (); return 0; }
#End If

Do you have something like this in manifest
B4X:
SetActivityAttribute (main, android:configChanges, "keyboard|keyboardHidden|orientation|screenSize")
 
Last edited:
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Try to use
That doesnt work, I get an error:
java.lang.RuntimeException: Method: getActivityHeight not found in: com.jmon.nameexplorer.main

Do you have something like this in manifest
No, this is what I have,
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

The only thing I have set is:
B4X:
#SupportedOrientations: portrait
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Ok, I found a workaround which makes me wonder even more what's wrong. o_O

pnlBottom is anchored at the bottom of the activity.
Capture.JPG


The strange thing is that Activity.Height doesn't return the same value as pnlBottom.top + pnlBottom.Height:
B4X:
Log(100%y) = 1018
Log(100%x) = 1080
Log(Activity.Height) = 1018
Log(Activity.Width) = 1080
Log(pnlBottom.top + pnlBottom.Height) = 1737

I'll use pnlBottom.top + pnlBottom.Height for the moment.

Thanks for your help
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Does it also happen?
I just tried, and no, it doesn't happen... The values are correct.
I loaded the same layout, libraries, also tested with the same project attributes, no problem....
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Ok I found why, it's because of the SlidingMenuWrapper.
B4X:
sm.Initialize("sm")
Dim Offset As Int = 100dip
sm.BehindOffset = Offset
sm.Mode = sm.LEFT
I just added that to a new project and that causes the problem.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Can you upload the project?
Here it is. The bug happens every time I lock and unlock the phone (with physical button).

Thank you.

[edit] I have Xperia E6653 and latest version of B4A.
 

Attachments

  • ActivityHeight_WithSlidingMenu.zip
    13.1 KB · Views: 138
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Does it happen if #IncludeTitle is set to True?
Yes, it happens.
B4X:
CREATE 100%y=1594
CREATE Activity.Height=1594

RESUME 100%y=875
RESUME Activity.Height=875
Maybe related to Sony phones ? Their lock screens are different, and after unlocking the app comes up from the bottom.

edit:
it happens even if I set :
B4X:
#SupportedOrientations: unspecified
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Do you need:
#FullScreen: False
That seems to fix the problem :eek:

Cool!

All my other apps are full screen, but I got some complaints! So I wanted this app to no be full screen....
 
Upvote 0
Top