Android Question know from what class is derived an object

Roberto P.

Well-Known Member
Licensed User
Longtime User
I need to know what class is derived an object of custom controls.

I know the function:

B4X:
If CallBack Is Activity Then

end if

specifically I need to know the class membership of the object that is passed in the custom controls.

B4X:
Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
   
    If CallBack Is Activity Then
        Log("è una activita")
    else if CallBack Is Panel Then
        Log("è un pannello")
    End If
   
End Sub

thanks
 

LucaMs

Expert
Licensed User
Longtime User
If you needed only to know:
If CallBack Is Activity Then

maybe you can use (or adapt) this routine (it is from module Scale):
B4X:
'Returns True If the View v Is an Activity otherwise False
'Needed to check if the view is a Panel or an Activity
Public Sub IsActivity(v As View) As Boolean
    Dim obj As Object
    obj = GetParent(v)
    If GetType(obj) = "android.widget.FrameLayout" Then
        Return True
    Else
        Return False
    End If
End Sub
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
It is difficult to distinguish between activities and panels because both of them are based on the same internal type.

What do you need it for?

I need to know what is the parent class of the object, to make the correct cast with the subject "vCallback"
So, how do I know which class an object belongs?
I hope it is clear
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…