Android Question Reflector.SetOnClickListener not working in release build

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have a class that keeps a reference to an ImageView (that is on the layout in my Main Activity) as one of its members. When I initialize the class, I use reflector to set the onClickListener for that ImageView to a sub that is also a member of the class.

In debug mode, it all works fine - the listener sub is called whenever the ImageView is tapped on. In release mode however, the listener is not called at all. There is no corresponding Click event in the Main Activity, so the tap is not being consumed there.

Here is the relevant code in the class:
B4X:
Public Sub Initialize(id As Long, image As ImageView, machineType As Int, machineName As String, bmp As Bitmap)
    mID = id
    mImage = image
    mType = machineType
    mName = machineName
    mBMP = bmp
   
    setMachineStatus(0, 0)
    Private r As Reflector
   
    r.Target = mImage
    r.SetOnClickListener("machineClick")
End Sub

Public Sub machineClick(viewtag As Object)
    cDlg.ShowAsync(mName.Trim, "OK", "", "", Null, True)
    cDlg.SetSize(100%x, 385dip)
    Wait For Dialog_Ready(pnl As Panel)
    pnl.LoadLayout("popup")
    pnl.Color = Colors.White
    lblStatus.Text = $"Status: ${getStatusString}"$
'    lblStatus.TextColor = mColor
    If mStatus = 15 Then 
        lblInfo1.Text = $"Time Remaining: ${formatTimeLeft}"$ 
        lblInfo1.Visible = True
    Else 
        lblInfo1.Visible = False
    End If
    formatMachineInfo
    Log(mName)
End Sub

I must be missing something...

- Colin.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Are you compiling in release (obfuscation) mode?

You need to add an underscore to the sub name. See the obfuscation tutorial.
Yes, that was the issue. Thanks Erel.
 
Upvote 0
Top