The Tricks of the Trade wiki entry shows this code:
The above works well, but I can't see how to use any of the various Reflection 'method' methods to invoke one of my B4A subs - is this possible please?
Example (in the main Activity):
Would someone point me in the right direction please? (And yes, I have a 'valid' use for this!)
Thanks,
Jim
B4X:
Sub Process_Globals
Dim debugMode As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Dim r As Reflector
debugMode = r.GetStaticField("anywheresoftware.b4a.BA", "debugMode")
End If
Log(debugMode)
End Sub
The above works well, but I can't see how to use any of the various Reflection 'method' methods to invoke one of my B4A subs - is this possible please?
Example (in the main Activity):
B4X:
sub MySub1
Log("MySub1")
end sub
sub Try
Dim r As Reflector
r.Target = Me
Log("Reflection version: " & r.Version)
' THESE ALL FAIL WITH a 'java.lang.NoSuchMethodException':
r.RunMethod("MySub1")
r.RunPublicmethod("MySub1", Null, Null)
r.RunStaticMethod("anywheresoftware.b4a.BA", "MySub1", Null, Null)
m = r.GetMethod("MySub1",Null)
end sub
Would someone point me in the right direction please? (And yes, I have a 'valid' use for this!)
Thanks,
Jim