Determine Device Type

Rusty

Well-Known Member
Licensed User
Longtime User
Is there a way, during Activity_Create/firsttime, to determine:
Device type
Device screen size/resolution
Device orientation
?
Thanks
 

alfcen

Well-Known Member
Licensed User
Longtime User
Please give this a try:

B4X:
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Log(lv)

As for device orientation:

B4X:
If Activity.Width > Activity.Height Then
  landscape = true
Else
  landscape = false
End If
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks, Erel. I discovered this and have a check in the Activity_Resume. This seems to work pretty well.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The best place to check it is in Activity_Create:
B4X:
Sub Activity_Create (FirstTime As Boolean)
  If FirstTime = True Then
    'here you should initialize process global objects
  End If
  'Load layout and configure it
  
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Log(lv)
...
End Sub
Activity_Create will always be called when the orientation is changed. Setting the layout in Activity_Resume will also work but is less efficient as Activity_Resume can be called many times (each time your activity becomes visible).
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks, Erel. Good information. Can you tell me what the purpose of the Activity_Resume multiple calls is.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top